From: Lennart Poettering Date: Fri, 2 Jul 2021 13:15:17 +0000 (+0200) Subject: hashmap: make sure hashmap_get_strv()+set_get_strv() work with a NULL object X-Git-Tag: v249~21 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=107e21635bb59a01bc92dda05211b03a7d40bde6;p=thirdparty%2Fsystemd.git hashmap: make sure hashmap_get_strv()+set_get_strv() work with a NULL object Before we invoke n_entries() we need to check for non-NULL here, like in all other calls to the helper function. Otherwise we'll crash when invoked with a NULL object, which we usually consider equivalent to an empty one though. --- diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c index 9ed69bd3d27..0decbb04e10 100644 --- a/src/basic/hashmap.c +++ b/src/basic/hashmap.c @@ -1761,6 +1761,9 @@ char** _hashmap_get_strv(HashmapBase *h) { Iterator i; unsigned idx, n; + if (!h) + return new0(char*, 1); + sv = new(char*, n_entries(h)+1); if (!sv) return NULL;