From d527b1a886175ad587f91db31b36c1bb0d7b7ad2 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 16 May 2020 16:14:13 +0100 Subject: [PATCH] uxucs.c: fix type of wcrtomb return value. wcrtomb returns a size_t, so it's silly to immediately assign it into an int variable. Apparently running gcc with LTO enabled points this out as an error. This was benign as far as I can see: the obvious risk of integer overflow could only happen if the OS wanted to convert a single wide character into more than 2^31 bytes, and the test of the return value against (size_t)-1 for an error check seems to work anyway in practice, although I suspect that's only because of implementation- defined behaviour in gcc at the point where the size_t is narrowed to a signed int. (cherry picked from commit 99f5fa34ab918894939c8aca00e44730223c0e54) --- unix/uxucs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unix/uxucs.c b/unix/uxucs.c index a3d6f5ba..c1d76a42 100644 --- a/unix/uxucs.c +++ b/unix/uxucs.c @@ -68,7 +68,7 @@ int wc_to_mb(int codepage, int flags, const wchar_t *wcstr, int wclen, memset(&state, 0, sizeof state); while (wclen > 0) { - int i = wcrtomb(output, wcstr[0], &state); + size_t i = wcrtomb(output, wcstr[0], &state); if (i == (size_t)-1 || i > n - mblen) break; memcpy(mbstr+n, output, i);