ftparchive/cachedb.cc: rewrite to fix the fixed length field
authorMichael Vogt <michael.vogt@ubuntu.com>
Thu, 22 Sep 2011 13:15:30 +0000 (15:15 +0200)
committerMichael Vogt <michael.vogt@ubuntu.com>
Thu, 22 Sep 2011 13:15:30 +0000 (15:15 +0200)
ftparchive/cachedb.cc

index 080c2bbcc1a2c5de62bfb0032cb85c77481337fc..24e3a1af864d66f6dcc265b2ec1ef066d0fc980f 100644 (file)
@@ -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) {