patch #75132 changes for bug#132230 (str_unescape and js_str_escape in jsstr.c ignore OOM errors) Written by Steven Cole, sr=bendan, r=khanson, a=asa. Handles an out of memory conditions more gracefully.

This commit is contained in:
khanson%netscape.com 2002-03-22 21:24:46 +00:00
Родитель 3578644699
Коммит 51645833cc
1 изменённых файлов: 4 добавлений и 0 удалений

Просмотреть файл

@ -355,6 +355,8 @@ js_str_escape(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval
} }
newchars = (jschar *) JS_malloc(cx, (newlength + 1) * sizeof(jschar)); newchars = (jschar *) JS_malloc(cx, (newlength + 1) * sizeof(jschar));
if (!newchars)
return JS_FALSE;
for (i = 0, ni = 0; i < length; i++) { for (i = 0, ni = 0; i < length; i++) {
if ((ch = chars[i]) < 128 && IS_OK(ch, mask)) { if ((ch = chars[i]) < 128 && IS_OK(ch, mask)) {
newchars[ni++] = ch; newchars[ni++] = ch;
@ -408,6 +410,8 @@ str_unescape(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
/* Don't bother allocating less space for the new string. */ /* Don't bother allocating less space for the new string. */
newchars = (jschar *) JS_malloc(cx, (length + 1) * sizeof(jschar)); newchars = (jschar *) JS_malloc(cx, (length + 1) * sizeof(jschar));
if (!newchars)
return JS_FALSE;
ni = i = 0; ni = i = 0;
while (i < length) { while (i < length) {
ch = chars[i++]; ch = chars[i++];