From fb7bc7380d78f5c0313ba947f746d1c9b31bd166 Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Sat, 3 Jan 2015 21:12:40 +0100 Subject: Fix number2*() functions As correctly pointed out by 'Nable80': "%llx" does not create the 0x prefix for the hex-string. In addition to that: snprintf() adds a terminating \0. --- src/FbTk/StringUtil.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/FbTk/StringUtil.cc b/src/FbTk/StringUtil.cc index 9cd2c9a..d6f2c8f 100644 --- a/src/FbTk/StringUtil.cc +++ b/src/FbTk/StringUtil.cc @@ -70,7 +70,7 @@ using std::transform; namespace { const size_t DIGITS10_ULONGLONGINT = 20; // ULLONG_MAX = 18446744073709551615 -const size_t DIGITS16_ULONGLONGINT = 18; // ULLONG_MAX = 0xffffffffffffffff +const size_t DIGITS16_ULONGLONGINT = 16; // ULLONG_MAX = ffffffffffffffff template int extractBigNumber(const char* in, T (*extractFunc)(const char*, char**, int), T& out) { @@ -173,15 +173,15 @@ int extractNumber(const std::string& in, unsigned long long& out) { std::string number2String(long long num) { - char s[DIGITS10_ULONGLONGINT]; - snprintf(s, sizeof(s), "%lld", num); - return std::string(s); + char s[DIGITS10_ULONGLONGINT+1]; + int n = snprintf(s, sizeof(s), "%lld", num); + return std::string(s, n); } std::string number2HexString(long long num) { - char s[DIGITS16_ULONGLONGINT]; - snprintf(s, sizeof(s), "%llx", num); - return std::string(s); + char s[DIGITS16_ULONGLONGINT+1]; + int n = snprintf(s, sizeof(s), "%llx", num); + return std::string(s, n); } -- cgit v0.11.2