]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
scan-build: truncate tinytest hexified outputs to 1024 bytes.
authorNick Mathewson <nickm@torproject.org>
Sat, 19 Apr 2014 16:44:31 +0000 (12:44 -0400)
committerNick Mathewson <nickm@torproject.org>
Sat, 19 Apr 2014 16:47:51 +0000 (12:47 -0400)
scan-build didn't like the unlimited version since we might need to
overflow size_t to hexify a string that took up half our address
space. (!)

src/ext/tinytest.c

index 3a8e331055015365f72c861157becfc6ae5ceb47..cc054ad34056bd7f98cdbe03d111615298555c7f 100644 (file)
@@ -478,16 +478,23 @@ tinytest_format_hex_(const void *val_, unsigned long len)
        const unsigned char *val = val_;
        char *result, *cp;
        size_t i;
+       int ellipses = 0;
 
        if (!val)
                return strdup("null");
-       if (!(result = malloc(len*2+1)))
+       if (len > 1024) {
+               ellipses = 3;
+               len = 1024;
+       }
+       if (!(result = malloc(len*2+4)))
                return strdup("<allocation failure>");
        cp = result;
        for (i=0;i<len;++i) {
                *cp++ = "0123456789ABCDEF"[val[i] >> 4];
                *cp++ = "0123456789ABCDEF"[val[i] & 0x0f];
        }
+       while (ellipses--)
+               *cp++ = '.';
        *cp = 0;
        return result;
 }