From ea407659042880bee65b3dca2ca77d5eb364bffa Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Wed, 11 Jan 2017 19:15:45 +0100 Subject: [PATCH] tweaks: rename two variables, and always pass a valid result back What is the point of parsing a number when you're not interested in the result? All callers of parse_num() pass a container for it. --- src/utils.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/utils.c b/src/utils.c index 56ee31b8..7a0641bf 100644 --- a/src/utils.c +++ b/src/utils.c @@ -85,25 +85,22 @@ int digits(ssize_t n) } #endif -/* Read a ssize_t from str, and store it in *val (if val is not NULL). - * On error, we return FALSE and don't change *val. Otherwise, we - * return TRUE. */ -bool parse_num(const char *str, ssize_t *val) +/* Read an integer from str. If it parses okay, store it in *result + * and return TRUE; otherwise, return FALSE. */ +bool parse_num(const char *str, ssize_t *result) { char *first_error; - ssize_t j; + ssize_t value; - /* The manual page for strtol() says this is required, and - * it looks like it is! */ + /* The manual page for strtol() says this is required. */ errno = 0; - j = (ssize_t)strtol(str, &first_error, 10); + value = (ssize_t)strtol(str, &first_error, 10); if (errno == ERANGE || *str == '\0' || *first_error != '\0') return FALSE; - if (val != NULL) - *val = j; + *result = value; return TRUE; }