Commit ea407659 authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

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.
No related merge requests found
Showing with 7 additions and 10 deletions
+7 -10
...@@ -85,25 +85,22 @@ int digits(ssize_t n) ...@@ -85,25 +85,22 @@ int digits(ssize_t n)
} }
#endif #endif
/* Read a ssize_t from str, and store it in *val (if val is not NULL). /* Read an integer from str. If it parses okay, store it in *result
* On error, we return FALSE and don't change *val. Otherwise, we * and return TRUE; otherwise, return FALSE. */
* return TRUE. */ bool parse_num(const char *str, ssize_t *result)
bool parse_num(const char *str, ssize_t *val)
{ {
char *first_error; char *first_error;
ssize_t j; ssize_t value;
/* The manual page for strtol() says this is required, and /* The manual page for strtol() says this is required. */
* it looks like it is! */
errno = 0; 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') if (errno == ERANGE || *str == '\0' || *first_error != '\0')
return FALSE; return FALSE;
if (val != NULL) *result = value;
*val = j;
return TRUE; return TRUE;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment