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:
mccabe%netscape.com
1999-05-12 09:04:38 +00:00
parent 64e9468cea
commit 7172b35aea
2 changed files with 8 additions and 2 deletions

View File

@@ -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;
}

View File

@@ -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;
}