From: Ben Pfaff Date: Sat, 12 Sep 2020 16:53:52 +0000 (-0700) Subject: i18n: Fix use of const qualifiers in create_iconv(). X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=db5d7699e90fe6d690b776bb945891f6c0601c97;p=pspp i18n: Fix use of const qualifiers in create_iconv(). Only the inbuf parameter of iconv() takes a const qualifier, on some POSIX nonconforming systems, but all of its parameters were qualified here, which caused warnings on those nonconforming systems. This fixes the problem. Found with win-iconv for mingw. --- diff --git a/src/libpspp/i18n.c b/src/libpspp/i18n.c index 31f07ed8da..fed6113503 100644 --- a/src/libpspp/i18n.c +++ b/src/libpspp/i18n.c @@ -107,18 +107,15 @@ create_iconv (const char* tocode, const char* fromcode) iconv_t bconv = iconv_open (tocode, "ASCII"); if (bconv != (iconv_t) -1) { - ICONV_CONST char *nullstr = strdup (""); - ICONV_CONST char *outbuf = strdup ("XXXXXXXX"); - ICONV_CONST char *snullstr = nullstr; - ICONV_CONST char *soutbuf = outbuf; - - size_t inbytes = 1; - const size_t bytes = 8; - size_t outbytes = bytes; - if (-1 != iconv (bconv, &nullstr, &inbytes, &outbuf, &outbytes)) - converter->null_char_width = bytes - outbytes; - free (snullstr); - free (soutbuf); + ICONV_CONST char inbuf[1] = ""; + ICONV_CONST char *inptr = inbuf; + size_t inbytes = sizeof inbuf; + + char outbuf[8]; + char *outptr = outbuf; + size_t outbytes = sizeof outbuf; + if (-1 != iconv (bconv, &inptr, &inbytes, &outptr, &outbytes)) + converter->null_char_width = outptr - outbuf; iconv_close (bconv); }