Bug 1491919 - fix use of uninitialised string, ideas by Henri Sivonen. r=jorgk DONTBUILD
authorBen Campbell <benc@thunderbird.net>
Mon, 24 Sep 2018 17:22:58 +1200
changeset 33219 149dde1772d65e32046d704401cda8acc69c4c86
parent 33218 08bf719c34e9a53cd4c1d2bf6f6ae2ed758acd13
child 33220 86e1a9121b5d5bf67043e611b356462214a67dba
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersjorgk
bugs1491919
Bug 1491919 - fix use of uninitialised string, ideas by Henri Sivonen. r=jorgk DONTBUILD
mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.cpp
--- a/mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.cpp
+++ b/mailnews/extensions/bayesian-spam-filter/src/nsBayesianFilter.cpp
@@ -838,22 +838,23 @@ void Tokenizer::tokenize(const char* aTe
             } else {
                 break;
             }
         }
     }
   }
 }
 
-// helper function to escape \n, \t, etc from a CString
+// helper function to un-escape \n, \t, etc from a CString
 void Tokenizer::UnescapeCString(nsCString& aCString)
 {
   nsAutoCString result;
 
   const char* readEnd = aCString.EndReading();
+  result.SetLength(aCString.Length());
   char* writeStart = result.BeginWriting();
   char* writeIter = writeStart;
 
   bool inEscape = false;
   for (const char* readIter = aCString.BeginReading(); readIter != readEnd; readIter++)
   {
     if (!inEscape)
     {
@@ -886,17 +887,17 @@ void Tokenizer::UnescapeCString(nsCStrin
           *(writeIter++) = '\r';
           break;
         default:
           // all other escapes are ignored
           break;
       }
     }
   }
-  result.SetLength(writeIter - writeStart);
+  result.Truncate(writeIter - writeStart);
   aCString.Assign(result);
 }
 
 Token* Tokenizer::copyTokens()
 {
   uint32_t count = countTokens();
   if (count > 0) {
     Token* tokens = new Token[count];