Bug 471540 - TM: "Assertion failure: cp >= buf" at homicideReport.php. r=gal.

--HG--
extra : rebase_source : 7f3bc4e8db9ce307360792b889943d8609e8ff6e
This commit is contained in:
Jason Orendorff 2009-01-08 17:09:16 -06:00
Родитель bf1fefb4f2
Коммит 3ff0d9cc39
3 изменённых файлов: 34 добавлений и 23 удалений

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

@ -298,8 +298,8 @@ num_toSource(JSContext *cx, uintN argc, jsval *vp)
#endif #endif
/* The buf must be big enough for MIN_INT to fit including '-' and '\0'. */ /* The buf must be big enough for MIN_INT to fit including '-' and '\0'. */
char * static char *
js_IntToCString(jsint i, jsint base, char *buf, size_t bufSize) IntToCString(jsint i, jsint base, char *buf, size_t bufSize)
{ {
char *cp; char *cp;
jsuint u; jsuint u;
@ -363,7 +363,7 @@ num_toString(JSContext *cx, uintN argc, jsval *vp)
return JS_FALSE; return JS_FALSE;
if (base < 2 || base > 36) { if (base < 2 || base > 36) {
char numBuf[12]; char numBuf[12];
char *numStr = js_IntToCString(base, 10, numBuf, sizeof numBuf); char *numStr = IntToCString(base, 10, numBuf, sizeof numBuf);
JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_RADIX, JS_ReportErrorNumber(cx, js_GetErrorMessage, NULL, JSMSG_BAD_RADIX,
numStr); numStr);
return JS_FALSE; return JS_FALSE;
@ -787,15 +787,21 @@ js_NewNumberInRootedValue(JSContext *cx, jsdouble d, jsval *vp)
return js_NewDoubleInRootedValue(cx, d, vp); return js_NewDoubleInRootedValue(cx, d, vp);
} }
char * /*
js_NumberToCString(JSContext *cx, jsdouble d, jsint base, char *buf, size_t bufSize) * Convert a number to C string. The buf must be large enough to accommodate
* the result, including '-' and '\0', if base == 10 or d is an integer that
* fits in 32 bits. The caller must free the resulting pointer if it does not
* point into buf.
*/
static char *
NumberToCString(JSContext *cx, jsdouble d, jsint base, char *buf, size_t bufSize)
{ {
jsint i; jsint i;
char *numStr; char *numStr;
JS_ASSERT(bufSize >= DTOSTR_STANDARD_BUFFER_SIZE); JS_ASSERT(bufSize >= DTOSTR_STANDARD_BUFFER_SIZE);
if (JSDOUBLE_IS_INT(d, i)) { if (JSDOUBLE_IS_INT(d, i)) {
numStr = js_IntToCString(i, base, buf, bufSize); numStr = IntToCString(i, base, buf, bufSize);
} else { } else {
if (base == 10) if (base == 10)
numStr = JS_dtostr(buf, bufSize, DTOSTR_STANDARD, 0, d); numStr = JS_dtostr(buf, bufSize, DTOSTR_STANDARD, 0, d);
@ -812,15 +818,25 @@ js_NumberToCString(JSContext *cx, jsdouble d, jsint base, char *buf, size_t bufS
static JSString * JS_FASTCALL static JSString * JS_FASTCALL
NumberToStringWithBase(JSContext *cx, jsdouble d, jsint base) NumberToStringWithBase(JSContext *cx, jsdouble d, jsint base)
{ {
char buf[DTOSTR_STANDARD_BUFFER_SIZE]; /*
* The longest possible result here that would need to fit in buf is
* (-0x80000000).toString(2), which has length 33. (This can produce
* longer results, but in those cases buf is not used; see comment at
* NumberToCString.)
*/
char buf[34];
char *numStr; char *numStr;
JSString *s;
if (base < 2 || base > 36) if (base < 2 || base > 36)
return NULL; return NULL;
numStr = js_NumberToCString(cx, d, base, buf, sizeof buf); numStr = NumberToCString(cx, d, base, buf, sizeof buf);
if (!numStr) if (!numStr)
return NULL; return NULL;
return JS_NewStringCopyZ(cx, numStr); s = JS_NewStringCopyZ(cx, numStr);
if (!(numStr >= buf && numStr < buf + sizeof buf))
free(numStr);
return s;
} }
JSString * JS_FASTCALL JSString * JS_FASTCALL

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

@ -182,20 +182,6 @@ js_NewNumberInRootedValue(JSContext *cx, jsdouble d, jsval *vp);
extern JSString * JS_FASTCALL extern JSString * JS_FASTCALL
js_NumberToString(JSContext *cx, jsdouble d); js_NumberToString(JSContext *cx, jsdouble d);
/*
* Convert int to C string. The buf must be big enough for MIN_INT to fit
* including '-' and '\0'.
*/
char *
js_IntToCString(jsint i, jsint base, char *buf, size_t bufSize);
/*
* Convert a number to C string. The buf must be at least
* DTOSTR_STANDARD_BUFFER_SIZE.
*/
char *
js_NumberToCString(JSContext *cx, jsdouble d, jsint base, char *buf, size_t bufSize);
/* /*
* Convert a value to a number. On exit JSVAL_IS_NULL(*vp) iff there was an * Convert a value to a number. On exit JSVAL_IS_NULL(*vp) iff there was an
* error. If on exit JSVAL_IS_NUMBER(*vp), then *vp holds the jsval that * error. If on exit JSVAL_IS_NUMBER(*vp), then *vp holds the jsval that

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

@ -2157,6 +2157,15 @@ function testNumToString() {
testNumToString.expected = "123456789,-123456789,123456789,-123456789,75bcd15,-75bcd15,21i3v9,-21i3v9"; testNumToString.expected = "123456789,-123456789,123456789,-123456789,75bcd15,-75bcd15,21i3v9,-21i3v9";
test(testNumToString); test(testNumToString);
function testLongNumToString() {
var s;
for (var i = 0; i < 5; i++)
s = (0x08000000).toString(2);
return s;
}
testLongNumToString = '1000000000000000000000000000';
test(testLongNumToString);
function testSubstring() { function testSubstring() {
for (var i = 0; i < 5; ++i) { for (var i = 0; i < 5; ++i) {
actual = "".substring(5); actual = "".substring(5);