strtoul of negative number
You better use cppreference.com for documentation it seems to be much more accurate:
if the minus sign was part of the input sequence, the numeric value calculated from the sequence of digits is negated as if by unary minus in the result type, which applies unsigned integer wraparound rules.
and as mentioned there optional plus or minus sign is a valid symbol
Per the POSIX standard:
Since
0
,{ULONG_MAX}
, and{ULLONG_MAX}
are returned on error and are also valid returns on success, an application wishing to check for error situations should seterrno
to0
, then callstrtoul()
orstrtoull()
, then checkerrno
.
You need to check errno
.