Fix a couple of out of range errors
These were detected using -fsanitize=undefined parsing values equal to INT_MAX and INT_MIN.
This commit is contained in:
parent
bd20573829
commit
3e5ecf1d2a
@ -23,6 +23,7 @@ options. The project adheres to semantic versioning.
|
||||
* Throw on invalid option syntax when beginning with a `-`.
|
||||
* Throw in `as` when option wasn't present.
|
||||
* Fix catching exceptions by reference.
|
||||
* Fix out of bounds errors parsing integers.
|
||||
|
||||
## 2.1.1
|
||||
|
||||
|
||||
@ -485,7 +485,7 @@ namespace cxxopts
|
||||
{
|
||||
if (negative)
|
||||
{
|
||||
if (u > static_cast<U>(-(std::numeric_limits<T>::min)()))
|
||||
if (u > -static_cast<U>((std::numeric_limits<T>::min)()))
|
||||
{
|
||||
throw argument_incorrect_type(text);
|
||||
}
|
||||
@ -523,7 +523,7 @@ namespace cxxopts
|
||||
// if we got to here, then `t` is a positive number that fits into
|
||||
// `R`. So to avoid MSVC C4146, we first cast it to `R`.
|
||||
// See https://github.com/jarro2783/cxxopts/issues/62 for more details.
|
||||
return -static_cast<R>(t);
|
||||
return -static_cast<R>(t-1)-1;
|
||||
}
|
||||
|
||||
template <typename R, typename T>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user