diff options
author | Mathias Gumz <akira@fluxbox.org> | 2015-01-03 20:12:40 (GMT) |
---|---|---|
committer | Mathias Gumz <akira@fluxbox.org> | 2015-01-03 20:33:20 (GMT) |
commit | fb7bc7380d78f5c0313ba947f746d1c9b31bd166 (patch) | |
tree | d289feda555f5ba67ac1899bd9dd3942d565e184 /src/FbTk | |
parent | 6a9c14e620fc276204a916e72073b2d716728c03 (diff) | |
download | fluxbox-fb7bc7380d78f5c0313ba947f746d1c9b31bd166.zip fluxbox-fb7bc7380d78f5c0313ba947f746d1c9b31bd166.tar.bz2 |
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.
Diffstat (limited to 'src/FbTk')
-rw-r--r-- | src/FbTk/StringUtil.cc | 14 |
1 files 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; | |||
70 | namespace { | 70 | namespace { |
71 | 71 | ||
72 | const size_t DIGITS10_ULONGLONGINT = 20; // ULLONG_MAX = 18446744073709551615 | 72 | const size_t DIGITS10_ULONGLONGINT = 20; // ULLONG_MAX = 18446744073709551615 |
73 | const size_t DIGITS16_ULONGLONGINT = 18; // ULLONG_MAX = 0xffffffffffffffff | 73 | const size_t DIGITS16_ULONGLONGINT = 16; // ULLONG_MAX = ffffffffffffffff |
74 | 74 | ||
75 | template <typename T> | 75 | template <typename T> |
76 | int extractBigNumber(const char* in, T (*extractFunc)(const char*, char**, int), T& out) { | 76 | 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) { | |||
173 | 173 | ||
174 | 174 | ||
175 | std::string number2String(long long num) { | 175 | std::string number2String(long long num) { |
176 | char s[DIGITS10_ULONGLONGINT]; | 176 | char s[DIGITS10_ULONGLONGINT+1]; |
177 | snprintf(s, sizeof(s), "%lld", num); | 177 | int n = snprintf(s, sizeof(s), "%lld", num); |
178 | return std::string(s); | 178 | return std::string(s, n); |
179 | } | 179 | } |
180 | 180 | ||
181 | std::string number2HexString(long long num) { | 181 | std::string number2HexString(long long num) { |
182 | char s[DIGITS16_ULONGLONGINT]; | 182 | char s[DIGITS16_ULONGLONGINT+1]; |
183 | snprintf(s, sizeof(s), "%llx", num); | 183 | int n = snprintf(s, sizeof(s), "%llx", num); |
184 | return std::string(s); | 184 | return std::string(s, n); |
185 | } | 185 | } |
186 | 186 | ||
187 | 187 | ||