Prevent NULL pointer in mem_copy (fixes #2753)

This commit is contained in:
Jupeyy 2020-09-06 16:29:20 +02:00
parent ef9260601e
commit aed4293040
2 changed files with 5 additions and 1 deletions

View file

@ -3223,8 +3223,11 @@ const char *str_next_token(const char *str, const char *delim, char *buffer, int
{
int len = 0;
const char *tok = str_token_get(str, delim, &len);
if(len < 0)
if(len < 0 || tok == NULL)
{
buffer[0] = '\0';
return NULL;
}
len = buffer_size > len ? len : buffer_size - 1;
mem_copy(buffer, tok, len);

View file

@ -173,6 +173,7 @@ TEST(Str, InList)
EXPECT_FALSE(str_in_list("", ",", "xyz"));
EXPECT_TRUE(str_in_list("FOO,,BAR", ",", ""));
EXPECT_TRUE(str_in_list("abc,,def", ",", "def"));
}
TEST(Str, StrFormat)