summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2019-06-15 17:21:06 +0200
committerSébastien Helleu <flashcode@flashtux.org>2019-06-15 17:21:06 +0200
commit866a29c7e63bbda24e04fc36b34bbd798a8c98db (patch)
tree33c50da6ddd1a39a3f918c6180207e48d0758ca8
parent95cbf3a48bfcf855f1d9a35fccda4ed6d3bafce1 (diff)
downloadweechat-866a29c7e63bbda24e04fc36b34bbd798a8c98db.zip
core: check that string pointer is not NULL in function "string_shared_get"
-rw-r--r--src/core/wee-string.c3
-rw-r--r--tests/unit/core/test-core-string.cpp5
2 files changed, 7 insertions, 1 deletions
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);