зеркало из https://github.com/mozilla/gecko-dev.git
Allocate 1 extra space and nul-terminate the string given to XPT_NewString. Thanks to Jim Dunn <jdunn@netscape.com> for suggesting this fix.
This commit is contained in:
Родитель
0d6eaf8a20
Коммит
636bfa81c1
|
@ -274,12 +274,15 @@ XPT_NewString(PRUint16 length, char *bytes)
|
|||
if (!str)
|
||||
return NULL;
|
||||
str->length = length;
|
||||
str->bytes = malloc(length);
|
||||
/* Alloc one extra to store the trailing nul. */
|
||||
str->bytes = malloc(length + 1);
|
||||
if (!str->bytes) {
|
||||
XPT_DELETE(str);
|
||||
return NULL;
|
||||
}
|
||||
memcpy(str->bytes, bytes, length);
|
||||
/* nul-terminate it. */
|
||||
str->bytes[length] = '\0';
|
||||
return str;
|
||||
}
|
||||
|
||||
|
|
|
@ -274,12 +274,15 @@ XPT_NewString(PRUint16 length, char *bytes)
|
|||
if (!str)
|
||||
return NULL;
|
||||
str->length = length;
|
||||
str->bytes = malloc(length);
|
||||
/* Alloc one extra to store the trailing nul. */
|
||||
str->bytes = malloc(length + 1);
|
||||
if (!str->bytes) {
|
||||
XPT_DELETE(str);
|
||||
return NULL;
|
||||
}
|
||||
memcpy(str->bytes, bytes, length);
|
||||
/* nul-terminate it. */
|
||||
str->bytes[length] = '\0';
|
||||
return str;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче