]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
utils: fix get_integer() logic
authorPedro Tammela <pctammela@mojatatu.com>
Sat, 19 Aug 2023 20:54:48 +0000 (17:54 -0300)
committerDavid Ahern <dsahern@kernel.org>
Sun, 20 Aug 2023 16:41:05 +0000 (10:41 -0600)
After 3a463c15, get_integer() doesn't return the converted value and
always writes 0 in 'val' in case of success.
Fix the logic so it writes the converted value in 'val'.

Fixes: 3a463c15 ("Add get_long utility and adapt get_integer accordingly"
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
lib/utils.c

index efa01668d797c69ef1b3896d5f86c36ffb6ac4c7..99ba7a2333d2d9dcb544388c04e4acf5b1a0a6e8 100644 (file)
@@ -142,7 +142,8 @@ int get_integer(int *val, const char *arg, int base)
 {
        long res;
 
-       res = get_long(NULL, arg, base);
+       if (get_long(&res, arg, base) < 0)
+               return -1;
 
        /* Outside range of int */
        if (res < INT_MIN || res > INT_MAX)