cxxopt/test
Dexter.k 654d63dfae
Avoid undefined std::abs(INT_MIN) in integer_parser (#498)
* Avoid undefined std::abs(INT_MIN) in integer_parser

When parsing a negative integer into a signed type whose minimum value
equals INTMAX_MIN (e.g. int64_t on typical platforms), integer_parser
computes the limit as std::abs(static_cast<intmax_t>(min())). Negating
INTMAX_MIN cannot be represented in intmax_t, so the std::abs call is
undefined behaviour. UBSan flags this on every negative int64_t parse,
including a trivial one like "-1":

  runtime error: negation of -9223372036854775808 cannot be represented
  in type 'long'; cast to an unsigned type to negate this value to itself

Build the same unsigned magnitude (|min| == max + 1 for two's-complement)
directly in the unsigned arithmetic type instead. For unsigned T the
expression wraps to 0, which matches the previous std::abs(0) value, so
behaviour for unsigned types is preserved.

* test: cover INT64_MIN parse and run parser tests under UBSan

* test: skip UBSan flags on Windows clang-cl/MinGW builds
2026-06-03 07:28:20 +10:00
..
add-subdirectory-test Added compatibility with CMake 4. (#451) 2025-03-17 17:46:27 +11:00
find-package-test Added compatibility with CMake 4. (#451) 2025-03-17 17:46:27 +11:00
.gitignore ignore built files 2016-08-26 08:26:42 +10:00
.tipiignore Added instructions to use cxxopts with tipi to INSTALL (#325) 2022-03-22 22:01:25 +11:00
CMakeLists.txt Avoid undefined std::abs(INT_MIN) in integer_parser (#498) 2026-06-03 07:28:20 +10:00
catch.hpp Update catch header 2024-07-16 09:29:45 +10:00
fuzz.cpp feat(fuzzer): Adds fuzz tests (#386) 2023-02-06 07:30:51 +11:00
link_a.cpp Cleanup uses of inline 2017-10-18 08:07:10 +11:00
link_b.cpp Cleanup uses of inline 2017-10-18 08:07:10 +11:00
main.cpp missing file 2017-05-31 17:57:27 +10:00
meson.build Add Meson buildsystem support (#424) 2026-01-12 18:00:29 +11:00
options.cpp Avoid undefined std::abs(INT_MIN) in integer_parser (#498) 2026-06-03 07:28:20 +10:00