[mapserver-commits] r9956 - branches/branch-5-6/mapserver

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


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

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



Modified: branches/branch-5-6/mapserver/HISTORY.TXT
===================================================================
--- branches/branch-5-6/mapserver/HISTORY.TXT	2010-03-19 18:25:24 UTC (rev 9955)
+++ branches/branch-5-6/mapserver/HISTORY.TXT	2010-03-19 18:25:33 UTC (rev 9956)
@@ -15,6 +15,8 @@
 Current Version (SVN branch-5-6):
 --------------------------------
 
+- Check error returns from mapstring functions (#2988)
+
 - Correct mutex locking problem with rasters with no inherent georef. (#3368) 
 
 - Fixed problem with isValidItem vs OGR special attributes (#3356)

Modified: branches/branch-5-6/mapserver/mapsde.c
===================================================================
--- branches/branch-5-6/mapserver/mapsde.c	2010-03-19 18:25:24 UTC (rev 9955)
+++ branches/branch-5-6/mapserver/mapsde.c	2010-03-19 18:25:33 UTC (rev 9956)
@@ -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: branches/branch-5-6/mapserver/mapstring.c
===================================================================
--- branches/branch-5-6/mapserver/mapstring.c	2010-03-19 18:25:24 UTC (rev 9955)
+++ branches/branch-5-6/mapserver/mapstring.c	2010-03-19 18:25:33 UTC (rev 9956)
@@ -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