Fixed potential bug with -MINIMUM_VALUE #1

Merged
EnilPajic merged 3 commits from patch-1-negative-minimum-value into master 2020-06-27 19:09:26 -04:00
EnilPajic commented 2020-06-26 15:44:08 -04:00 (Migrated from github.com)

Original code had something like N < 0 ? -N : N which could fail if N has minimum value of appropriate type. For example, in original code this could fail:

const long long int LL_MIN = std::numeric_limits<long long int>::min(); //probably: -9223372036854775808
static const char *number = to_string<LL_MIN, 10>;

Also note that this code relies on "modulo on negative first operands" which was implementation defined in C++03 and before, but with C++11 and later it is defined by standard (see ISO14882:2011(e)), and this code anyway targets C++17 so we're safe here.

Original code had something like `N < 0 ? -N : N` which could fail if `N` has minimum value of appropriate type. For example, in original code this could fail: ```cpp const long long int LL_MIN = std::numeric_limits<long long int>::min(); //probably: -9223372036854775808 static const char *number = to_string<LL_MIN, 10>; ``` Also note that this code relies on "modulo on negative first operands" which was implementation defined in C++03 and before, but with C++11 and later it is defined by standard (see `ISO14882:2011(e)`), and this code anyway targets C++17 so we're safe here.
Sign in to join this conversation.
No description provided.