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
Prev Previous commit
Next Next commit
lib/getrange.c: getrange(): Return early to reduce indentation
Signed-off-by: Alejandro Colomar <[email protected]>
  • Loading branch information
alejandro-colomar committed Apr 16, 2024
commit 505dbaec75c8db27278c3d6168a340517e68c255
60 changes: 30 additions & 30 deletions lib/getrange.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,38 +48,38 @@ getrange(const char *range,
return -1;
*has_max = true;

/* -<long> */
} else {
errno = 0;
*min = strtoul_noneg(range, &endptr, 10);
if (endptr == range || 0 != errno)
return 0; /* -<long> */
}

errno = 0;
*min = strtoul_noneg(range, &endptr, 10);
if (endptr == range || 0 != errno)
return -1;
*has_min = true;

switch (*endptr) {
case '\0':
/* <long> */
*has_max = true;
*max = *min;
break;
case '-':
endptr++;
if ('\0' == *endptr)
return 0; /* <long>- */
if (!isdigit(*endptr))
return -1;
*has_min = true;

switch (*endptr) {
case '\0':
/* <long> */
*has_max = true;
*max = *min;
break;
case '-':
endptr++;
if ('\0' == *endptr)
return 0; /* <long>- */
if (!isdigit(*endptr))
return -1;

errno = 0;
*max = strtoul_noneg(endptr, &endptr, 10);
if ('\0' != *endptr || 0 != errno)
return -1;
*has_max = true;

/* <long>-<long> */
break;
default:

errno = 0;
*max = strtoul_noneg(endptr, &endptr, 10);
if ('\0' != *endptr || 0 != errno)
return -1;
}
*has_max = true;

/* <long>-<long> */
break;
default:
return -1;
}

return 0;
Expand Down