Add basic error checking to parsing nr from rw=randrw:<nr>, etc
authoraggieNick02 <nick@pcpartpicker.com>
Fri, 1 Sep 2023 22:01:05 +0000 (17:01 -0500)
committeraggieNick02 <nick@pcpartpicker.com>
Fri, 1 Sep 2023 22:01:05 +0000 (17:01 -0500)
commit2e0a52594ed11e738d2402a3e22d05ec5597535a
tree4db30b95277fb5738e65a8978e26c8745cb6c58a
parent4a0c766c69ddfe5231d65f2676e97333ba89ab2b
Add basic error checking to parsing nr from rw=randrw:<nr>, etc

Previously this was parsed by just doing atoi(). This returns 0 or has
undefined behavior in error cases.

Silently getting a 0 for nr is not great. In fact, 0 (or less) should
likely not be allowed for nr; while the code handles it, the effective
result is that the randomness is gone - all I/O becomes sequential. It
makes sense to prohibit 0 as an nr value in the random case.

We leverage str_to_decimal to do our parsing instead of atoi. It isn't
perfect, but it is a lot more resilient than atoi, and used in other
similar places. We can then return an error when parsing fails, and also
return an error when the parsed numeric value is outside of the ranges
that can be stored in the unsigned int used for nr, along with when nr
is 0.

Fixes #1622

Signed-off-by: Nick Neumann nick@pcpartpicker.com
options.c