From a52d11fbc14f8fb10deb93a5898f53a633acbec1 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 22 Sep 2011 14:17:13 +0200 Subject: * ftparchive/cachedb.cc: - fix buffersize in bytes2hex --- ftparchive/cachedb.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ftparchive') diff --git a/ftparchive/cachedb.cc b/ftparchive/cachedb.cc index 7e4c2e9fe..080c2bbcc 100644 --- a/ftparchive/cachedb.cc +++ b/ftparchive/cachedb.cc @@ -297,7 +297,7 @@ bool CacheDB::LoadContents(bool const &GenOnly) /*}}}*/ static string bytes2hex(uint8_t *bytes, size_t length) { - char space[65]; + char space[129]; 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]); -- cgit v1.2.3 From 76ef756a6babf9fa217bed2f7618cb00140b4306 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 22 Sep 2011 15:15:30 +0200 Subject: ftparchive/cachedb.cc: rewrite to fix the fixed length field --- ftparchive/cachedb.cc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'ftparchive') diff --git a/ftparchive/cachedb.cc b/ftparchive/cachedb.cc index 080c2bbcc..24e3a1af8 100644 --- a/ftparchive/cachedb.cc +++ b/ftparchive/cachedb.cc @@ -297,11 +297,15 @@ bool CacheDB::LoadContents(bool const &GenOnly) /*}}}*/ static string bytes2hex(uint8_t *bytes, size_t length) { - char space[129]; - 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) { -- cgit v1.2.3