core: ensure length is not negative in function string_strndup

v2.8-utf8proc
Sébastien Helleu 2017-04-22 15:15:54 +02:00
parent 572678100b
commit 94355e2e38
2 changed files with 3 additions and 1 deletions

View File

@ -76,7 +76,7 @@ string_strndup (const char *string, int length)
{
char *result;
if (!string)
if (!string || (length < 0))
return NULL;
if ((int)strlen (string) < length)

View File

@ -123,6 +123,8 @@ TEST(String, Duplicate)
POINTERS_EQUAL(NULL, string_strndup (NULL, 0));
POINTERS_EQUAL(NULL, string_strndup (str_test, -1));
str = string_strndup (str_test, 0);
CHECK(str);
CHECK(str != str_test);