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

svn at osgeo.org svn at osgeo.org
Fri Mar 19 14:25:25 EDT 2010


Author: pramsey
Date: 2010-03-19 14:25:24 -0400 (Fri, 19 Mar 2010)
New Revision: 9955

Modified:
   branches/branch-5-4/mapserver/HISTORY.TXT
   branches/branch-5-4/mapserver/mapsde.c
   branches/branch-5-4/mapserver/mapstring.c
Log:
Check error returns from mapstring functions (#2988)



Modified: branches/branch-5-4/mapserver/HISTORY.TXT
===================================================================
--- branches/branch-5-4/mapserver/HISTORY.TXT	2010-03-18 18:31:38 UTC (rev 9954)
+++ branches/branch-5-4/mapserver/HISTORY.TXT	2010-03-19 18:25:24 UTC (rev 9955)
@@ -14,6 +14,8 @@
 Current Version:
 ----------------
 
+- Check error returns from mapstring functions (#2988)
+
 - Avoid memory error when building SQL bbox (#3324)
 
 - Determine PgSQL version in a more backwards compatible way (#3291)

Modified: branches/branch-5-4/mapserver/mapsde.c
===================================================================
--- branches/branch-5-4/mapserver/mapsde.c	2010-03-18 18:31:38 UTC (rev 9954)
+++ branches/branch-5-4/mapserver/mapsde.c	2010-03-19 18:25:24 UTC (rev 9955)
@@ -753,6 +753,13 @@
                     else
                         shape->values[i] = msConvertWideStringToUTF8((const wchar_t*) wide, "UTF-16LE");
                     msFree(wide);
+                    if (!shape->values[i]) {  /* There was an error */
+                        msSetError( MS_SDEERR,
+                                 "msConvertWideStringToUTF8()==NULL.",
+                                 "sdeGetRecord()");
+                        shape->values[i] = (char *)malloc(itemdefs[i].size*sizeof(char)+1);
+                        shape->values[i][0] = '\0'; /* empty string */
+                    }                    
                 }
                 break;
 #endif

Modified: branches/branch-5-4/mapserver/mapstring.c
===================================================================
--- branches/branch-5-4/mapserver/mapstring.c	2010-03-18 18:31:38 UTC (rev 9954)
+++ branches/branch-5-4/mapserver/mapstring.c	2010-03-19 18:25:24 UTC (rev 9955)
@@ -1504,8 +1504,8 @@
 char* msConvertWideStringToUTF8 (const wchar_t* string, const char* encoding) {
 #ifdef USE_ICONV
 
-    int bconvFailed = MS_TRUE;
     char* output = NULL;
+    char* errormessage = NULL;
     iconv_t cd = NULL;
     size_t nStr;
     size_t nInSize;
@@ -1536,27 +1536,41 @@
         nOutSize = nBufferSize;
         if ((iconv_t)-1 != cd)
         {  
-           nInSize = sizeof (wchar_t)*nStr;
-           pszUTF8 = output;
-           pwszWide = string;
-           nConv = iconv(cd, (char **)&pwszWide, &nInSize, &pszUTF8, &nOutSize);
-           if ((size_t)-1 != nConv &&  nOutSize != nBufferSize)
-               bconvFailed = MS_FALSE;
-           iconv_close(cd);
+            nInSize = sizeof (wchar_t)*nStr;
+            pszUTF8 = output;
+            pwszWide = string;
+            nConv = iconv(cd, (char **)&pwszWide, &nInSize, &pszUTF8, &nOutSize);
+            if ((size_t)-1 != nConv &&  nOutSize != nBufferSize) {
+                switch (errno) {
+                    case E2BIG:
+                    errormessage = "There is not sufficient room in buffer";
+                    break;
+                    case EILSEQ:
+                    errormessage = "An invalid multibyte sequence has been encountered in the input";
+                    break;
+                    case EINVAL:
+                    errormessage = "An incomplete multibyte sequence has been encountered in the input";
+                    break;
+                    default:
+                    errormessage = "Unknown";
+                    break;
+                }
+                msSetError(MS_MISCERR, "Unable to convert string in encoding '%s' to UTF8 %s",
+                                       "msConvertWideStringToUTF8()",
+                           encoding,errormessage);
+                iconv_close(cd);
+                msFree(output);
+                return NULL;
+            }           
+            iconv_close(cd);
         } else {
             msSetError(MS_MISCERR, "Encoding not supported by libiconv (%s).", 
                                    "msConvertWideStringToUTF8()", 
                                    encoding);
+            msFree(output);
             return NULL;
         }
    
-        if (bconvFailed) {
-            msFree(output);
-            output = NULL;
-            msSetError(MS_MISCERR, "Unable to convert string in encoding '%s' to UTF8",
-                                   "msConvertWideStringToUTF8()",
-                                   encoding);
-        }
     } else {
         /* we were given a NULL wide string, nothing we can do here */
         return NULL;



More information about the mapserver-commits mailing list