]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
string.c: Handle invalid loglevels gracefully.
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 27 Dec 2015 23:03:38 +0000 (23:03 +0000)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 10 Jan 2016 12:00:01 +0000 (13:00 +0100)
Public functions should always return a proper error code on
failure. Returning -1 is asking for trouble.

error.h
string.c

diff --git a/error.h b/error.h
index 40e097e33cd180fae9b1f3709dcd362a563ffd81..75532ea2518a93aa7e0cbcca4dec18cb0d3a5bd8 100644 (file)
--- 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 \
index c35285153fdadf031fafb544aea4affdf066a86d..c820bdca3fd1ca37695354aa03024b4d384da765 100644 (file)
--- 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)