[mapserver-commits] r9977 - branches/branch-5-4/mapserver

svn at osgeo.org svn at osgeo.org
Mon Mar 22 14:01:08 EDT 2010


Author: pramsey
Date: 2010-03-22 14:01:08 -0400 (Mon, 22 Mar 2010)
New Revision: 9977

Modified:
   branches/branch-5-4/mapserver/mapstring.c
Log:
Fix backwards handling of iconv errors (#2988)



Modified: branches/branch-5-4/mapserver/mapstring.c
===================================================================
--- branches/branch-5-4/mapserver/mapstring.c	2010-03-22 18:01:00 UTC (rev 9976)
+++ branches/branch-5-4/mapserver/mapstring.c	2010-03-22 18:01:08 UTC (rev 9977)
@@ -1446,7 +1446,7 @@
   iconv_t cd = NULL;
   const char *inp;
   char *outp, *out = NULL;
-  size_t len, bufsize, bufleft, status;
+  size_t len, bufsize, bufleft, iconv_status;
 
 #ifdef USE_FRIBIDI
   if(fribidi_parse_charset ((char*)encoding))
@@ -1476,11 +1476,11 @@
   outp = out;
 
   bufleft = bufsize;
-  status = -1;
+  iconv_status = -1;
 
   while (len > 0){
-    status = iconv(cd, (char**)&inp, &len, &outp, &bufleft);
-    if(status == -1){
+    iconv_status = iconv(cd, (char**)&inp, &len, &outp, &bufleft);
+    if(iconv_status == -1){
       msFree(out);
       iconv_close(cd);
       return strdup(string);
@@ -1510,7 +1510,7 @@
     size_t nStr;
     size_t nInSize;
     size_t nOutSize;
-    size_t nConv;
+    size_t iconv_status = -1;
     size_t nBufferSize;
 
     char* pszUTF8 = NULL;
@@ -1522,7 +1522,7 @@
         nBufferSize = ((nStr * 6) + 1);
         output = (char*) malloc (nBufferSize);
         if (output == NULL) {
-            msSetError(MS_MEMERR, NULL, "msGetEncodedString()");
+            msSetError(MS_MEMERR, NULL, "msConvertWideStringToUTF8()");
             return NULL;
         }
         if (nStr == 0) {
@@ -1539,8 +1539,8 @@
             nInSize = sizeof (wchar_t)*nStr;
             pszUTF8 = output;
             pwszWide = string;
-            nConv = iconv(cd, (char **)&pwszWide, &nInSize, &pszUTF8, &nOutSize);
-            if ((size_t)-1 != nConv &&  nOutSize != nBufferSize) {
+            iconv_status = iconv(cd, (char **)&pwszWide, &nInSize, &pszUTF8, &nOutSize);
+            if ((size_t)-1 == iconv_status) {
                 switch (errno) {
                     case E2BIG:
                     errormessage = "There is not sufficient room in buffer";



More information about the mapserver-commits mailing list