Signed down cast negates usefulness of preceding bounds check
pgoodman opened this issue · 0 comments
pgoodman commented
Describe the bug
The following code checks that strtol
doesn't read a negative number from the environment variable.
What the code should really do is check that ((int16_t) nthreads) > 0
. That is, strtol
could read in 65535
, which is a non-negative long
number. Then, the (highlighted) cast to an int16_t
would interpret this as -1
.
To Reproduce
Set BLOSC_NTHREADS
environment variable to 65535
.
System information:
- OS: macOS
- Compiler: Clang
- Version: 16