diff --git a/src/base/system.c b/src/base/system.c index 8f398b542..90b597cef 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -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); diff --git a/src/test/str.cpp b/src/test/str.cpp index 5785a334b..d5ab83e6f 100644 --- a/src/test/str.cpp +++ b/src/test/str.cpp @@ -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)