Bug 637859. Anchor a string for a bit. r=cdleary, a=bsmedberg THUNDERBIRD_3_3a3_BUILD1 THUNDERBIRD_3_3a3_RELEASE
authorJeff Walden <jwalden@mit.edu>
Thu, 03 Mar 2011 09:37:18 -0800
changeset 63323 290712e55ade
parent 63322 770e2709cff5
child 63324 e56ecd8b3a68
child 63404 7fd8f2b01b17
push idunknown
push userunknown
push dateunknown
reviewerscdleary, bsmedberg
bugs637859
milestone2.0b13pre
Bug 637859. Anchor a string for a bit. r=cdleary, a=bsmedberg
js/src/jsregexp.cpp
--- a/js/src/jsregexp.cpp
+++ b/js/src/jsregexp.cpp
@@ -635,30 +635,32 @@ regexp_toString(JSContext *cx, uintN arg
  */
 static JSString *
 EscapeNakedForwardSlashes(JSContext *cx, JSString *unescaped)
 {
     size_t oldLen = unescaped->length();
     const jschar *oldChars = unescaped->getChars(cx);
     if (!oldChars)
         return NULL;
+    JS::Anchor<JSString *> anchor(unescaped);
 
     js::Vector<jschar, 128> newChars(cx);
     for (const jschar *it = oldChars; it < oldChars + oldLen; ++it) {
         if (*it == '/' && (it == oldChars || it[-1] != '\\')) {
             if (!newChars.length()) {
                 if (!newChars.reserve(oldLen + 1))
                     return NULL;
-                newChars.append(oldChars, size_t(it - oldChars));
+                JS_ALWAYS_TRUE(newChars.append(oldChars, size_t(it - oldChars)));
             }
-            newChars.append('\\');
+            if (!newChars.append('\\'))
+                return NULL;
         }
 
-        if (newChars.length())
-            newChars.append(*it);
+        if (!newChars.empty() && !newChars.append(*it))
+            return NULL;
     }
 
     if (newChars.length()) {
         size_t len = newChars.length();
         if (!newChars.append('\0'))
             return NULL;
         jschar *chars = newChars.extractRawBuffer();
         JSString *escaped = js_NewString(cx, chars, len);