Bug 1491919 - fix use of uninitialised string, ideas by Henri Sivonen. r+a=jorgk DONTBUILD
authorBen Campbell <benc@thunderbird.net>
Mon, 24 Sep 2018 17:22:58 +1200
changeset 31828 4730874c3c0e2af951e98f1f3902f0f0e9a2817d
parent 31827 d44d43ef68d9ee37d08db418f4229bcb1d2ea0ec
child 31829 d10016aa761f650b158d7a088e1d7518069ff968
push id79
push usermozilla@jorgk.com
push dateMon, 24 Sep 2018 19:53:15 +0000
treeherdercomm-esr60@4730874c3c0e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1491919
Bug 1491919 - fix use of uninitialised string, ideas by Henri Sivonen. r+a=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
@@ -834,22 +834,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)
     {
@@ -882,17 +883,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];