From 6002161b05811321e03e1ac1cf537af6c190c172 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sun, 28 Jul 2013 21:03:39 -0700 Subject: [PATCH] Fix numberToString for limit cases --- .../modules/beast_core/text/beast_String.cpp | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/Subtrees/beast/modules/beast_core/text/beast_String.cpp b/Subtrees/beast/modules/beast_core/text/beast_String.cpp index f151a24673..f55bb510d4 100644 --- a/Subtrees/beast/modules/beast_core/text/beast_String.cpp +++ b/Subtrees/beast/modules/beast_core/text/beast_String.cpp @@ -361,18 +361,34 @@ namespace NumberToStringConverters // pass in a pointer to the END of a buffer.. static char* numberToString (char* t, const int64 n) noexcept { - *--t = 0; - int64 v = (n >= 0) ? n : -n; - - do + if (n > 0) { - *--t = (char) ('0' + (int) (v % 10)); - v /= 10; + *--t = 0; + uint64 v = static_cast (n); - } while (v > 0); + do + { + *--t = (char) ('0' + (int) (v % 10)); + v /= 10; + + } + while (v > 0); + } + else + { + *--t = 0; + uint64 v = ((uint64)(-(n + 1)) + 1); + + do + { + *--t = (char) ('0' + (int) (v % 10)); + v /= 10; + + } + while (v > 0); - if (n < 0) *--t = '-'; + } return t; }