From b06f0cc6258b7135182f3b29244a7df0ab203ab6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 6 Nov 2018 12:06:45 +0100 Subject: [PATCH] parse-util: allow parse_boolean() to take a NULL argument It's pretty useful to allow parse_boolean() to take a NULL argument and return an error in that case, rather than abort. i.e. making this a runtime rather than programming error allows us to shorten code elsewhere. --- src/basic/parse-util.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c index 718357e290..5b4e94c134 100644 --- a/src/basic/parse-util.c +++ b/src/basic/parse-util.c @@ -20,7 +20,8 @@ #include "string-util.h" int parse_boolean(const char *v) { - assert(v); + if (!v) + return -EINVAL; if (streq(v, "1") || strcaseeq(v, "yes") || strcaseeq(v, "y") || strcaseeq(v, "true") || strcaseeq(v, "t") || strcaseeq(v, "on")) return 1;