i18n: Fix use of const qualifiers in create_iconv().
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 12 Sep 2020 16:53:52 +0000 (09:53 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 12 Sep 2020 16:54:07 +0000 (09:54 -0700)
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.

src/libpspp/i18n.c

index 31f07ed8da0234d24bf8e53b5b77f377098ebaeb..fed6113503328e7e2c232947d45dc6d67081f92a 100644 (file)
@@ -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);
     }