From 107e21635bb59a01bc92dda05211b03a7d40bde6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 2 Jul 2021 15:15:17 +0200 Subject: 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. --- src/basic/hashmap.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c index 9ed69bd3d2..0decbb04e1 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; -- cgit v1.2.1