Handle allocation error in strndup to avoid access violation.

Return NULL before calling strncpy.
Platforms with HAVE_STRNDUP are not affected.
This commit is contained in:
Yoichi NAKAYAMA
2012-03-10 23:15:37 +09:00
parent b78eaf4e43
commit 194397b6d6
2 changed files with 9 additions and 0 deletions

View File

@@ -50,6 +50,8 @@
{
size_t strsize = strnlen(__string, __n);
char *newstr = (char *)malloc(strsize + 1);
if (newstr == NULL)
return NULL;
strncpy(newstr, __string, strsize);
newstr[strsize] = 0;