Bug 744541. r=bz
authorMats Palmgren <matspal@gmail.com>
Tue, 17 Apr 2012 18:53:06 +0200
changeset 91878 6c0fdf2079a96dc609f000d5f4943d181de5c144
parent 91877 4a5d25e138e23585c50cf6fdd1f2093908f92da2
child 91879 328b56d0b34c1a66427111df96a2f98d45e71f5b
push id690
push usertim.taubert@gmx.de
push dateThu, 19 Apr 2012 08:49:11 +0000
treeherderfx-team@a9b543de6b67 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs744541
milestone14.0a1
Bug 744541. r=bz
xpcom/io/nsNativeCharsetUtils.cpp
--- a/xpcom/io/nsNativeCharsetUtils.cpp
+++ b/xpcom/io/nsNativeCharsetUtils.cpp
@@ -559,19 +559,19 @@ nsNativeCharsetConverter::UnicodeToNativ
 {
     size_t res = 0;
     size_t inLeft = (size_t) *inputLeft * 2;
     size_t outLeft = (size_t) *outputLeft;
 
     if (gUnicodeToNative != INVALID_ICONV_T) {
         res = xp_iconv(gUnicodeToNative, (const char **) input, &inLeft, output, &outLeft);
 
+        *inputLeft = inLeft / 2;
+        *outputLeft = outLeft;
         if (res != (size_t) -1) {
-            *inputLeft = inLeft / 2;
-            *outputLeft = outLeft;
             return NS_OK;
         }
 
         NS_ERROR("iconv failed");
 
         // reset converter
         xp_iconv_reset(gUnicodeToNative);
     }
@@ -602,30 +602,31 @@ nsNativeCharsetConverter::UnicodeToNativ
                 }
                 else
                     NS_ERROR("conversion from utf-8 to native failed");
                 break;
             }
             inLeft -= sizeof(PRUnichar);
         }
 
+        (*input) += (*inputLeft - inLeft / 2);
+        *inputLeft = inLeft / 2;
+        *outputLeft = outLeft;
         if (res != (size_t) -1) {
-            (*input) += (*inputLeft - inLeft/2);
-            *inputLeft = inLeft/2;
-            *outputLeft = outLeft;
             return NS_OK;
         }
 
         // reset converters
         xp_iconv_reset(gUnicodeToUTF8);
         xp_iconv_reset(gUTF8ToNative);
     }
 #endif
 
     // fallback: truncate and hope for the best
+    // XXX This is lame and we have to do better.
     utf16_to_isolatin1(input, inputLeft, output, outputLeft);
 
     return NS_OK;
 }
 
 bool
 nsNativeCharsetConverter::IsNativeUTF8()
 {