commit ea407659042880bee65b3dca2ca77d5eb364bffa
parent 16a7fd4bfc7858500f6fc549e35809d67e31dae7
Author: Benno Schulenberg <bensberg@justemail.net>
Date: Wed, 11 Jan 2017 19:15:45 +0100
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.
Diffstat:
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git 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;
}