all repos — fluxbox @ fb7bc7380d78f5c0313ba947f746d1c9b31bd166

custom fork of the fluxbox windowmanager

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.
Mathias Gumz akira@fluxbox.org
commit

fb7bc7380d78f5c0313ba947f746d1c9b31bd166

parent

6a9c14e620fc276204a916e72073b2d716728c03

1 files changed, 7 insertions(+), 7 deletions(-)

jump to
M src/FbTk/StringUtil.ccsrc/FbTk/StringUtil.cc

@@ -70,7 +70,7 @@

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 <typename T> int extractBigNumber(const char* in, T (*extractFunc)(const char*, char**, int), T& out) {

@@ -173,15 +173,15 @@

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); }