From 0f15a55530553b2acf397fc137caa0c7f3e8b131 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 27 Dec 2015 23:03:38 +0000 Subject: [PATCH] string.c: Handle invalid loglevels gracefully. Public functions should always return a proper error code on failure. Returning -1 is asking for trouble. --- error.h | 1 + string.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/error.h b/error.h index 40e097e3..75532ea2 100644 --- a/error.h +++ b/error.h @@ -396,6 +396,7 @@ extern const char **para_errlist[]; PARA_ERROR(SIZE_PREFIX, "bad size prefix"), \ PARA_ERROR(REGEX, "regular expression error"), \ PARA_ERROR(ARG_NOT_FOUND, "argument not found in arg vector"), \ + PARA_ERROR(BAD_LL, "invalid loglevel"), \ #define EXEC_ERRORS \ diff --git a/string.c b/string.c index c3528515..c820bdca 100644 --- a/string.c +++ b/string.c @@ -633,7 +633,7 @@ int get_loglevel_by_name(const char *txt) return LL_CRIT; if (loglevel_equal(txt, "emerg")) return LL_EMERG; - return -1; + return -E_BAD_LL; } static int get_next_word(const char *buf, const char *delim, char **word) -- 2.30.2