b=513789 comparison of unsigned expression < 0 is always false in mozSpellChecker.cpp r=mkaply
authorKarl Tomlinson <karlt+@karlt.net>
Thu, 03 Sep 2009 08:44:32 +1200
changeset 32198 b06c1085caabf8f1c1c0cc5ef63e62bf732aad38
parent 32197 d809cc77d823d73f5eaa9f4a419e0cceddaf52d6
child 32199 19b213c1cc316baf3f4714585d50e3eb7a0ee2e8
push idunknown
push userunknown
push dateunknown
reviewersmkaply
bugs513789
milestone1.9.3a1pre
b=513789 comparison of unsigned expression < 0 is always false in mozSpellChecker.cpp r=mkaply
extensions/spellcheck/src/mozSpellChecker.cpp
extensions/spellcheck/src/mozSpellChecker.h
--- a/extensions/spellcheck/src/mozSpellChecker.cpp
+++ b/extensions/spellcheck/src/mozSpellChecker.cpp
@@ -84,17 +84,17 @@ mozSpellChecker::SetDocument(nsITextServ
 
 
 NS_IMETHODIMP 
 mozSpellChecker::NextMisspelledWord(nsAString &aWord, nsTArray<nsString> *aSuggestions)
 {
   if(!aSuggestions||!mConverter)
     return NS_ERROR_NULL_POINTER;
 
-  PRUint32 selOffset;
+  PRInt32 selOffset;
   PRInt32 begin,end;
   nsresult result;
   result = SetupDoc(&selOffset);
   PRBool isMisspelled,done;
   if (NS_FAILED(result))
     return result;
 
   while( NS_SUCCEEDED(mTsDoc->IsDone(&done)) && !done )
@@ -169,17 +169,17 @@ NS_IMETHODIMP
 mozSpellChecker::Replace(const nsAString &aOldWord, const nsAString &aNewWord, PRBool aAllOccurrences)
 {
   if(!mConverter)
     return NS_ERROR_NULL_POINTER;
 
   nsAutoString newWord(aNewWord); // sigh
 
   if(aAllOccurrences){
-    PRUint32 selOffset;
+    PRInt32 selOffset;
     PRInt32 startBlock,currentBlock,currOffset;
     PRInt32 begin,end;
     PRBool done;
     nsresult result;
     nsAutoString str;
 
     // find out where we are
     result = SetupDoc(&selOffset);
@@ -197,19 +197,20 @@ mozSpellChecker::Replace(const nsAString
       {
         result = mTsDoc->GetCurrentTextBlock(&str);
         do{
           result = mConverter->FindNextWord(str.get(),str.Length(),currOffset,&begin,&end);
           if(NS_SUCCEEDED(result)&&(begin != -1)){
             if (aOldWord.Equals(Substring(str, begin, end-begin))) {
               // if we are before the current selection point but in the same block
               // move the selection point forwards
-              if((currentBlock == startBlock)&&(begin < (PRInt32) selOffset)){
-                selOffset += (aNewWord.Length() - aOldWord.Length());
-                if(selOffset < 0) selOffset=0;
+              if((currentBlock == startBlock)&&(begin < selOffset)){
+                selOffset +=
+		  PRInt32(aNewWord.Length()) - PRInt32(aOldWord.Length());
+                if(selOffset < begin) selOffset=begin;
               }
               mTsDoc->SetSelection(begin, end-begin);
               mTsDoc->InsertText(&newWord);
               mTsDoc->GetCurrentTextBlock(&str);
               end += (aNewWord.Length() - aOldWord.Length());  // recursion was cute in GEB, not here.
             }
           }
           currOffset = end;
@@ -383,17 +384,17 @@ mozSpellChecker::SetCurrentDictionary(co
   nsCOMPtr<mozISpellI18NManager> serv(do_GetService("@mozilla.org/spellchecker/i18nmanager;1", &res));
   if(serv && NS_SUCCEEDED(res)){
     res = serv->GetUtil(language.get(),getter_AddRefs(mConverter));
   }
   return res;
 }
 
 nsresult
-mozSpellChecker::SetupDoc(PRUint32 *outBlockOffset)
+mozSpellChecker::SetupDoc(PRInt32 *outBlockOffset)
 {
   nsresult  rv;
 
   nsITextServicesDocument::TSDBlockSelectionStatus blockStatus;
   PRInt32 selOffset;
   PRInt32 selLength;
   *outBlockOffset = 0;
 
--- a/extensions/spellcheck/src/mozSpellChecker.h
+++ b/extensions/spellcheck/src/mozSpellChecker.h
@@ -83,15 +83,15 @@ protected:
   nsClassHashtable<nsStringHashKey, nsCString> mDictionariesMap;
 
   nsString mDictionaryName;
   nsCString *mCurrentEngineContractId;
   nsCOMPtr<mozISpellCheckingEngine>  mSpellCheckingEngine;
   PRBool mFromStart;
   nsTArray<nsString> mIgnoreList;
 
-  nsresult SetupDoc(PRUint32 *outBlockOffset);
+  nsresult SetupDoc(PRInt32 *outBlockOffset);
 
   nsresult GetCurrentBlockIndex(nsITextServicesDocument *aDoc, PRInt32 *outBlockIndex);
 
   nsresult InitSpellCheckDictionaryMap();
 };
 #endif // mozSpellChecker_h__