summaryrefslogtreecommitdiff
path: root/ftparchive
diff options
context:
space:
mode:
authorMichael Vogt <egon@debian-devbox>2011-09-24 10:49:49 +0200
committerMichael Vogt <egon@debian-devbox>2011-09-24 10:49:49 +0200
commit324fc8af296953857ebfc76deaadd4d224e081e3 (patch)
tree07ea5a5d114ceefd8e72888af51804bef653b48f /ftparchive
parent44e5b709e5116a892be48a1ad8eac255e6f69881 (diff)
* ftparchive/cachedb.cc:
- fix buffersize in bytes2hex * ftparchive/cachedb.cc: - make buffer fully dynamic (thanks to Colin Watson)
Diffstat (limited to 'ftparchive')
-rw-r--r--ftparchive/cachedb.cc14
1 files changed, 9 insertions, 5 deletions
diff --git a/ftparchive/cachedb.cc b/ftparchive/cachedb.cc
index b04244347..6573fa264 100644
--- a/ftparchive/cachedb.cc
+++ b/ftparchive/cachedb.cc
@@ -294,11 +294,15 @@ bool CacheDB::LoadContents(bool const &GenOnly)
/*}}}*/
static string bytes2hex(uint8_t *bytes, size_t length) {
- char space[65];
- if (length * 2 > sizeof(space) - 1) length = (sizeof(space) - 1) / 2;
- for (size_t i = 0; i < length; i++)
- snprintf(&space[i*2], 3, "%02x", bytes[i]);
- return string(space);
+ char buf[3];
+ string space;
+
+ space.reserve(length*2 + 1);
+ for (size_t i = 0; i < length; i++) {
+ snprintf(buf, sizeof(buf), "%02x", bytes[i]);
+ space.append(buf);
+ }
+ return space;
}
static inline unsigned char xdig2num(char const &dig) {