From 866a29c7e63bbda24e04fc36b34bbd798a8c98db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sat, 15 Jun 2019 17:21:06 +0200 Subject: [PATCH] core: check that string pointer is not NULL in function "string_shared_get" --- src/core/wee-string.c | 3 +++ tests/unit/core/test-core-string.cpp | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 10e2bcaca..6741f9e66 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -3616,6 +3616,9 @@ string_shared_get (const char *string) char *key; int length; + if (!string) + return NULL; + if (!string_hashtable_shared) { /* diff --git a/tests/unit/core/test-core-string.cpp b/tests/unit/core/test-core-string.cpp index 1c792efc9..1f8938091 100644 --- a/tests/unit/core/test-core-string.cpp +++ b/tests/unit/core/test-core-string.cpp @@ -1839,7 +1839,10 @@ TEST(CoreString, Shared) const char *str1, *str2, *str3; int count; - count = string_hashtable_shared->items_count; + count = (string_hashtable_shared) ? + string_hashtable_shared->items_count : 0; + + POINTERS_EQUAL(NULL, string_shared_get (NULL)); str1 = string_shared_get ("this is a test"); CHECK(str1);