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
Showing only changes of commit 5baf5d3dae - Show all commits

View File

@ -23,7 +23,7 @@ struct to_string_t {
// fits to the number perfectly.
char buf[([] {
unsigned int len = N >= 0 ? 1 : 2;
for (auto n = N < 0 ? -N : N; n; len++, n /= base);
for (auto n = N; n; len++, n /= base);
return len;
}())];
@ -33,8 +33,8 @@ struct to_string_t {
constexpr to_string_t() {
auto ptr = buf + sizeof(buf) / sizeof(buf[0]);
*--ptr = '\0';
for (auto n = N < 0 ? -N : N; n; n /= base)
*--ptr = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[n % base];
for (auto n = N; n; n /= base)
*--ptr = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[(N < 0 ? -1 : 1) * (n % base)];
if (N < 0)
*--ptr = '-';
}