Set correct output params. Bug 634257, r=emk, a=bsmedberg

This commit is contained in:
Simon Montagu 2011-02-20 11:04:28 +02:00
parent 170b9aaba4
commit ec7b1f996e

View File

@ -63,16 +63,13 @@ UTF16ConvertToUnicode(PRUint8& aState, PRUint8& aOddByte,
switch(aState) {
case STATE_FOUND_BOM:
if (*aSrcLength < 2)
return NS_ERROR_ILLEGAL_INPUT;
NS_ASSERTION(*aSrcLength > 1, "buffer too short");
src+=2;
aState = STATE_NORMAL;
break;
case STATE_FIRST_CALL: // first time called
if (*aSrcLength < 2)
return NS_ERROR_ILLEGAL_INPUT;
NS_ASSERTION(*aSrcLength > 1, "buffer too short");
// Eliminate BOM (0xFEFF). Note that different endian case is taken care
// of in |Convert| of LE and BE converters. Here, we only have to
// deal with the same endian case. That is, 0xFFFE (byte-swapped BOM) is
@ -222,14 +219,18 @@ NS_IMETHODIMP
nsUTF16BEToUnicode::Convert(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength)
{
if(STATE_FIRST_CALL == mState && *aSrcLength < 2)
{
*aSrcLength=0;
*aDestLength=0;
return NS_ERROR_ILLEGAL_INPUT;
}
#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 (*aSrcLength < 2)
return NS_ERROR_ILLEGAL_INPUT;
if(0xFFFE == *((PRUnichar*)aSrc)) {
// eliminate BOM (on LE machines, BE BOM is 0xFFFE)
mState = STATE_FOUND_BOM;
@ -257,14 +258,18 @@ NS_IMETHODIMP
nsUTF16LEToUnicode::Convert(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength)
{
if(STATE_FIRST_CALL == mState && *aSrcLength < 2)
{
*aSrcLength=0;
*aDestLength=0;
return NS_ERROR_ILLEGAL_INPUT;
}
#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 (*aSrcLength < 2)
return NS_ERROR_ILLEGAL_INPUT;
if(0xFFFE == *((PRUnichar*)aSrc)) {
// eliminate BOM (on BE machines, LE BOM is 0xFFFE)
mState = STATE_FOUND_BOM;
@ -300,12 +305,15 @@ NS_IMETHODIMP
nsUTF16ToUnicode::Convert(const char * aSrc, PRInt32 * aSrcLength,
PRUnichar * aDest, PRInt32 * aDestLength)
{
if(STATE_FIRST_CALL == mState && *aSrcLength < 2)
{
*aSrcLength=0;
*aDestLength=0;
return NS_ERROR_ILLEGAL_INPUT;
}
if(STATE_FIRST_CALL == mState) // first time called
{
mState = STATE_NORMAL;
if (*aSrcLength < 2)
return NS_ERROR_ILLEGAL_INPUT;
// 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])) {