From 69aa236de9f7c63cc4ddccfc6a229b12b5eeb2b4 Mon Sep 17 00:00:00 2001 From: "rickg%netscape.com" Date: Tue, 24 Nov 1998 02:38:21 +0000 Subject: [PATCH] changed ToInteger() so that it returns an error properly git-svn-id: svn://10.0.0.236/trunk@15226 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/base/src/nsString.cpp | 7 +++++-- mozilla/string/obsolete/nsString.cpp | 7 +++++-- mozilla/xpcom/ds/nsString.cpp | 7 +++++-- mozilla/xpcom/string/obsolete/nsString.cpp | 7 +++++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/mozilla/base/src/nsString.cpp b/mozilla/base/src/nsString.cpp index fd541aa0486..1c5154abd00 100644 --- a/mozilla/base/src/nsString.cpp +++ b/mozilla/base/src/nsString.cpp @@ -545,7 +545,7 @@ float nsString::ToFloat(PRInt32* aErrorCode) const * @update gess 10/01/98 * @param aErrorCode will contain error if one occurs * @param aRadix tells us what base to expect the string in. - * @return int rep of string value + * @return int rep of string value; aErrorCode gets set too: NS_OK, NS_ERROR_ILLEGAL_VALUE */ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const { PRInt32 result = 0; @@ -555,6 +555,8 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const { PRInt32 theShift=0; PRInt32 theMult=1; + *aErrorCode = (0= mStr) { theChar = *cp; @@ -587,13 +589,14 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const { break; } else{ + *aErrorCode=NS_ERROR_ILLEGAL_VALUE; + result=0; break; } result+=digit*theMult; theMult*=aRadix; } - *aErrorCode = NS_OK; return result; } diff --git a/mozilla/string/obsolete/nsString.cpp b/mozilla/string/obsolete/nsString.cpp index fd541aa0486..1c5154abd00 100644 --- a/mozilla/string/obsolete/nsString.cpp +++ b/mozilla/string/obsolete/nsString.cpp @@ -545,7 +545,7 @@ float nsString::ToFloat(PRInt32* aErrorCode) const * @update gess 10/01/98 * @param aErrorCode will contain error if one occurs * @param aRadix tells us what base to expect the string in. - * @return int rep of string value + * @return int rep of string value; aErrorCode gets set too: NS_OK, NS_ERROR_ILLEGAL_VALUE */ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const { PRInt32 result = 0; @@ -555,6 +555,8 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const { PRInt32 theShift=0; PRInt32 theMult=1; + *aErrorCode = (0= mStr) { theChar = *cp; @@ -587,13 +589,14 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const { break; } else{ + *aErrorCode=NS_ERROR_ILLEGAL_VALUE; + result=0; break; } result+=digit*theMult; theMult*=aRadix; } - *aErrorCode = NS_OK; return result; } diff --git a/mozilla/xpcom/ds/nsString.cpp b/mozilla/xpcom/ds/nsString.cpp index fd541aa0486..1c5154abd00 100644 --- a/mozilla/xpcom/ds/nsString.cpp +++ b/mozilla/xpcom/ds/nsString.cpp @@ -545,7 +545,7 @@ float nsString::ToFloat(PRInt32* aErrorCode) const * @update gess 10/01/98 * @param aErrorCode will contain error if one occurs * @param aRadix tells us what base to expect the string in. - * @return int rep of string value + * @return int rep of string value; aErrorCode gets set too: NS_OK, NS_ERROR_ILLEGAL_VALUE */ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const { PRInt32 result = 0; @@ -555,6 +555,8 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const { PRInt32 theShift=0; PRInt32 theMult=1; + *aErrorCode = (0= mStr) { theChar = *cp; @@ -587,13 +589,14 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const { break; } else{ + *aErrorCode=NS_ERROR_ILLEGAL_VALUE; + result=0; break; } result+=digit*theMult; theMult*=aRadix; } - *aErrorCode = NS_OK; return result; } diff --git a/mozilla/xpcom/string/obsolete/nsString.cpp b/mozilla/xpcom/string/obsolete/nsString.cpp index fd541aa0486..1c5154abd00 100644 --- a/mozilla/xpcom/string/obsolete/nsString.cpp +++ b/mozilla/xpcom/string/obsolete/nsString.cpp @@ -545,7 +545,7 @@ float nsString::ToFloat(PRInt32* aErrorCode) const * @update gess 10/01/98 * @param aErrorCode will contain error if one occurs * @param aRadix tells us what base to expect the string in. - * @return int rep of string value + * @return int rep of string value; aErrorCode gets set too: NS_OK, NS_ERROR_ILLEGAL_VALUE */ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const { PRInt32 result = 0; @@ -555,6 +555,8 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const { PRInt32 theShift=0; PRInt32 theMult=1; + *aErrorCode = (0= mStr) { theChar = *cp; @@ -587,13 +589,14 @@ PRInt32 nsString::ToInteger(PRInt32* aErrorCode,PRInt32 aRadix) const { break; } else{ + *aErrorCode=NS_ERROR_ILLEGAL_VALUE; + result=0; break; } result+=digit*theMult; theMult*=aRadix; } - *aErrorCode = NS_OK; return result; }