Permalink
Browse files

Bug 637859. Anchor a string for a bit. r=cdleary, a=bsmedberg

  • Loading branch information...
1 parent cc99f71 commit e974b414d62193fe7dd000e4131621e6fd4b11fe @jswalden jswalden committed Mar 3, 2011
Showing with 6 additions and 4 deletions.
  1. +6 −4 js/src/jsregexp.cpp
View
10 js/src/jsregexp.cpp
@@ -640,20 +640,22 @@ EscapeNakedForwardSlashes(JSContext *cx, JSString *unescaped)
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()) {

0 comments on commit e974b41

Please sign in to comment.