diff --git a/modules/beast_core/text/beast_String.cpp b/modules/beast_core/text/beast_String.cpp index 6d010ab40e..5d4648c559 100644 --- a/modules/beast_core/text/beast_String.cpp +++ b/modules/beast_core/text/beast_String.cpp @@ -376,7 +376,7 @@ namespace NumberToStringConverters // pass in a pointer to the END of a buffer.. static char* numberToString (char* t, const int64 n) noexcept { - if (n > 0) + if (n >= 0) return printDigits (t, static_cast (n)); // NB: this needs to be careful not to call -std::numeric_limits::min(), @@ -393,7 +393,7 @@ namespace NumberToStringConverters static char* numberToString (char* t, const int n) noexcept { - if (n > 0) + if (n >= 0) return printDigits (t, static_cast (n)); // NB: this needs to be careful not to call -std::numeric_limits::min(), @@ -2214,6 +2214,24 @@ public: expect (String::toHexString ((int64) 0x1234abcd).equalsIgnoreCase ("1234abcd")); expect (String::toHexString ((short) 0x12ab).equalsIgnoreCase ("12ab")); + expectEquals (String (int (0)), "0"); + expectEquals (String (short (0)), "0"); + expectEquals (String (int64 (0)), "0"); + expectEquals (String ((unsigned int) 0), "0"); + expectEquals (String ((unsigned short) 0), "0"); + expectEquals (String (uint64 (0)), "0"); + + expectEquals (String (int (-1)), "-1"); + expectEquals (String (short (-1)), "-1"); + expectEquals (String (int64 (-1)), "-1"); + + expectEquals (String (int (1)), "1"); + expectEquals (String (short (1)), "1"); + expectEquals (String (int64 (1)), "1"); + expectEquals (String ((unsigned int) 1), "1"); + expectEquals (String ((unsigned short) 1), "1"); + expectEquals (String (uint64 (1)), "1"); + unsigned char data[] = { 1, 2, 3, 4, 0xa, 0xb, 0xc, 0xd }; expect (String::toHexString (data, 8, 0).equalsIgnoreCase ("010203040a0b0c0d")); expect (String::toHexString (data, 8, 1).equalsIgnoreCase ("01 02 03 04 0a 0b 0c 0d"));