[mapserver-commits] r9957 - trunk/mapserver

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


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

Modified:
   trunk/mapserver/HISTORY.TXT
   trunk/mapserver/mapsde.c
   trunk/mapserver/mapstring.c
Log:
Check error returns from mapstring functions (#2988)



Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT	2010-03-19 18:25:33 UTC (rev 9956)
+++ trunk/mapserver/HISTORY.TXT	2010-03-19 18:25:46 UTC (rev 9957)
@@ -14,6 +14,8 @@
 Current Version (SVN trunk):
 ----------------------------
 
+- Check error returns from mapstring functions (#2988)
+
 - Add support for multiliple srs in  WFS 1.1.0 (#3227)
 
 - Fixed PHP/MapScript owsRequestObj->loadParams() method when using php in a non cgi/fcgi/cli mode. (#1975)

Modified: trunk/mapserver/mapsde.c
===================================================================
--- trunk/mapserver/mapsde.c	2010-03-19 18:25:33 UTC (rev 9956)
+++ trunk/mapserver/mapsde.c	2010-03-19 18:25:46 UTC (rev 9957)
@@ -762,6 +762,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: trunk/mapserver/mapstring.c
===================================================================
--- trunk/mapserver/mapstring.c	2010-03-19 18:25:33 UTC (rev 9956)
+++ trunk/mapserver/mapstring.c	2010-03-19 18:25:46 UTC (rev 9957)
@@ -1676,8 +1676,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;
@@ -1708,27 +1708,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