Don't return NS_ERROR_ILLEGAL_INPUT when given an empty source buffer. (Bug 638236) r=smontagu a2.0=blocking
authorL. David Baron <dbaron@dbaron.org>
Wed, 02 Mar 2011 23:21:06 -0800
changeset 63311 f76fac273005
parent 63310 7570423a050f
child 63312 39982a2ba344
child 63485 d2fb0b03b86b
push idunknown
push userunknown
push dateunknown
reviewerssmontagu
bugs638236
milestone2.0b13pre
Don't return NS_ERROR_ILLEGAL_INPUT when given an empty source buffer. (Bug 638236) r=smontagu a2.0=blocking
intl/uconv/ucvlatin/nsUCS2BEToUnicode.cpp
--- a/intl/uconv/ucvlatin/nsUCS2BEToUnicode.cpp
+++ b/intl/uconv/ucvlatin/nsUCS2BEToUnicode.cpp
@@ -216,19 +216,20 @@ nsUTF16ToUnicodeBase::GetMaxLength(const
 
 
 NS_IMETHODIMP
 nsUTF16BEToUnicode::Convert(const char * aSrc, PRInt32 * aSrcLength,
                             PRUnichar * aDest, PRInt32 * aDestLength)
 {
     if(STATE_FIRST_CALL == mState && *aSrcLength < 2)
     {
+      nsresult res = (*aSrcLength == 0) ? NS_OK : NS_ERROR_ILLEGAL_INPUT;
       *aSrcLength=0;
       *aDestLength=0;
-      return NS_ERROR_ILLEGAL_INPUT;
+      return res;
     }
 #ifdef IS_LITTLE_ENDIAN
     // Remove the BOM if we're little-endian. The 'same endian' case with the
     // leading BOM will be taken care of by |UTF16ConvertToUnicode|.
     if(STATE_FIRST_CALL == mState) // Called for the first time.
     {
       mState = STATE_NORMAL;
       if(0xFFFE == *((PRUnichar*)aSrc)) {
@@ -255,19 +256,20 @@ nsUTF16BEToUnicode::Convert(const char *
 }
 
 NS_IMETHODIMP
 nsUTF16LEToUnicode::Convert(const char * aSrc, PRInt32 * aSrcLength,
                             PRUnichar * aDest, PRInt32 * aDestLength)
 {
     if(STATE_FIRST_CALL == mState && *aSrcLength < 2)
     {
+      nsresult res = (*aSrcLength == 0) ? NS_OK : NS_ERROR_ILLEGAL_INPUT;
       *aSrcLength=0;
       *aDestLength=0;
-      return NS_ERROR_ILLEGAL_INPUT;
+      return res;
     }
 #ifdef IS_BIG_ENDIAN
     // Remove the BOM if we're big-endian. The 'same endian' case with the
     // leading BOM will be taken care of by |UTF16ConvertToUnicode|.
     if(STATE_FIRST_CALL == mState) // first time called
     {
       mState = STATE_NORMAL;
       if(0xFFFE == *((PRUnichar*)aSrc)) {
@@ -302,19 +304,20 @@ nsUTF16ToUnicode::Reset()
 }
 
 NS_IMETHODIMP
 nsUTF16ToUnicode::Convert(const char * aSrc, PRInt32 * aSrcLength,
                           PRUnichar * aDest, PRInt32 * aDestLength)
 {
     if(STATE_FIRST_CALL == mState && *aSrcLength < 2)
     {
+      nsresult res = (*aSrcLength == 0) ? NS_OK : NS_ERROR_ILLEGAL_INPUT;
       *aSrcLength=0;
       *aDestLength=0;
-      return NS_ERROR_ILLEGAL_INPUT;
+      return res;
     }
     if(STATE_FIRST_CALL == mState) // first time called
     {
       mState = STATE_NORMAL;
       // check if BOM (0xFEFF) is at the beginning, remove it if found, and
       // set mEndian accordingly.
       if(0xFF == PRUint8(aSrc[0]) && 0xFE == PRUint8(aSrc[1])) {
         mState = STATE_FOUND_BOM;