* 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
* fix: Overwrite m_positional_set in parse_positional()
* feat: Allow append in positionals and fix discrepancy between m_positional and m_positional_set during replace
* feat: Add test for short options parsing
* fix: Update option parsing to allow = with short options
* fix: Fix custom option parsing in case of CXXOPTS_NO_REGEX
* docs: Add badges
* docs: Replace travis badge with github's official badge
* docs: Use img shield badge so that we can print 'Build|Passing' instead of 'Cmake|Passing'
* meson: Add a Meson based build system
This is primarily intended to be useful for projects using Meson wishing
to consume cxxopts as a subproject. By hosting the files upstream users
get the benefit of automatic parity with the CMake based install
provided by an OS vendor or distribution.
The implementation attempts to mirror the CMake build as much as
possible, with the exception of generating the cmake-config files, which
Meson doesn't currently support. It uses a small python script to parse
the cxxopts.hpp header to extract the version, due to a concious design
decision of Meson to leave such complex logic to external scripting
languages like Python.
* CI: add basic Meson testing
I've tried to be a bit more minimal here than the CMake tests are, since
there's already a good cross section of testing there. For Meson, I just
want to touch test each of the major platforms to ensure that it works
* fix: Use non deprecated upload-artifact action version
* fix: Use branch name in build workflow, use latest checkout action, use cd bulid as job steps doesn't preserve current directories between themselves.
* fix: remove non-existent main branch, remove deprecated ubuntu-20, removed deprecated macos-11 and macos-12, setup g++-9 and g++-10 if not exists, use latest checkout action
* Move `result` up and return it
This allows `gcc` to elide the copy in the return and keeps it from
warning with `-Wnvro` enabled.
* Remove harmful dtor definition
The definition of the dtor is not necessary and actually harmful since
the definition of a class's implicit copy constructor is deprecated if
that class has a user-declared constructor as of C++11. Compilers can
warn about this with `-Wdeprecated`.
---------
Co-authored-by: Christoph Weiss <weiss@wsoptics.de>
* cmake: set PROJECT_DESCRIPTION and PROJECT_HOMEPAGE_URL after project()
Otherwise they are set to an empty string.
* cmake: set the pkg-config URL field
Since the information is already there to set it.
* cmake: use CMAKE_INSTALL_DATAROOTDIR if CMAKE_LIBRARY_ARCHITECTURE is unset
This causes files on NixOS to be put in the proper architecture
independent place, which otherwise was selecting the architecture
dependent location.
* cmake: Properly set pkg-config requires when configured with ICU
In this case the pkg-config file needs to set icu-cu in the `Required`
field, and needs to add the flag `-DCXXOPTS_USE_UNICODE` to the `Cflags`
field.
* cmake: cxxopts is not arch independent when built with ICU support
Since it links to an architecture dependent ICU
Fixes#290.
Checking for overflow should be done before integer overflows.
There are two checks:
(result > limit / base) is used for limits greater than rounded up to base,
e.g. for 65535 it will activate for 65540 and higher.
(result * base > limit - digit) is used for limit+1 to limit+n below
next base rounded number, e.g. 65536 up to 65539.