Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some getrange() simplification #980

Merged
merged 9 commits into from
May 4, 2024
Next Next commit
lib/getrange.c: getrange(): Small refactor
Set *has_{min,max} = false at the begining, so we only need to set them
to true later.

This means we set these variables on error, which we didn't do before,
but since we return -1 on error and ignore (don't use) the pointees at
call site, that's fine.

Signed-off-by: Alejandro Colomar <[email protected]>
  • Loading branch information
alejandro-colomar committed Apr 16, 2024
commit 81ceae0dfe1c682b58dd46096f9e530332fc9ce1
5 changes: 3 additions & 2 deletions lib/getrange.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ getrange(const char *range,
if (NULL == range)
return -1;

*has_min = false;
*has_max = false;

if ('-' == range[0]) {
if (!isdigit(range[1]))
return -1;
Expand All @@ -46,7 +49,6 @@ getrange(const char *range,
return -1;

/* -<long> */
*has_min = false;
*has_max = true;
*max = n;
} else {
Expand All @@ -68,7 +70,6 @@ getrange(const char *range,
if ('\0' == *endptr) {
/* <long>- */
*has_min = true;
*has_max = false;
*min = n;
} else if (!isdigit (*endptr)) {
return -1;
Expand Down