Allocate 1 extra space and nul-terminate the string given to XPT_NewString. Thanks to Jim Dunn <jdunn@netscape.com> for suggesting this fix.
git-svn-id: svn://10.0.0.236/trunk@31269 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user