From: Andre Noll Date: Sun, 27 Dec 2015 23:03:38 +0000 (+0000) Subject: string.c: Handle invalid loglevels gracefully. X-Git-Tag: v0.5.6~63 X-Git-Url: http://git.tuebingen.mpg.de/?a=commitdiff_plain;h=0f15a55530553b2acf397fc137caa0c7f3e8b131;hp=5da8c2e0d33f25579c804c3856cd8716486baee5;p=paraslash.git string.c: Handle invalid loglevels gracefully. Public functions should always return a proper error code on failure. Returning -1 is asking for trouble. --- 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)