[bugs] [PATCH] Fix integer parsing

bug + bug = nobug?
---
The 'is_all_digit(val + 1)' looked suspicious. If is_all_digit(NULL) returns
true, "+" and "-" will be accepted as integers, if false, single-digit integers
will be rejected. It does return true, but should return false.

 src/config.c | 8 +++++---
 src/utils.c  | 3 ++-
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/config.c b/src/config.c
index c46d718..f8eee98 100644
--- a/src/config.c
+++ b/src/config.c
@@ -151,12 +151,14 @@ static int config_parse_unsigned(unsigned *dest, const char *val)
 
 static int config_parse_int(int *dest, const char *val)
 {
-	if ((*val == '+' || *val == '-' || isdigit(*val))
-	    && is_all_digit(val + 1))
+	char *cp = (char *)val;
+
+	if (*val == '+' || *val == '-')
+		cp++;
+	if (is_all_digit(cp))
 		*dest = atoi(val);
 	else
 		return 0;
-
 	return 1;
 }
 
diff --git a/src/utils.c b/src/utils.c
index d5800c8..387f1a3 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -337,11 +337,12 @@ print_in_middle(WINDOW * win, int starty, int startx, int width,
 /* checks if a string is only made of digits */
 int is_all_digit(const char *string)
 {
+	if (!*string)
+		return 0;
 	for (; *string; string++) {
 		if (!isdigit((int)*string))
 			return 0;
 	}
-
 	return 1;
 }
 
-- 
2.14.2.666.gea220ee40

Links