Skip to content

Commit

Permalink
slice: disambiguate errno to handle EINVAL
Browse files Browse the repository at this point in the history
strtol is allowed to set EINVAL for an empty string as long as it
returns zero, cover that case.
  • Loading branch information
trws committed Nov 16, 2023
1 parent 3eab33d commit 741c82e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/common/libutil/slice.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ static int parse_int (char **cp, int def, char sep, int *value)

errno = 0;
v = strtol (*cp, &endptr, 10);
if (errno != 0)
// standard says EINVAL may be set if zero is returned for nothing parsed
if (v != 0 && errno != 0)
return -1;
if (endptr == *cp) { // no digits
if ((*cp)[0] == sep)
Expand Down

0 comments on commit 741c82e

Please sign in to comment.