scan-build: truncate tinytest hexified outputs to 1024 bytes.

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. (!)
This commit is contained in:
Nick Mathewson 2014-04-19 12:44:31 -04:00
parent 4d51dcda2f
commit 9c9e07963d

View File

@ -478,16 +478,23 @@ tinytest_format_hex_(const void *val_, unsigned long len)
const unsigned char *val = val_; const unsigned char *val = val_;
char *result, *cp; char *result, *cp;
size_t i; size_t i;
int ellipses = 0;
if (!val) if (!val)
return strdup("null"); 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>"); return strdup("<allocation failure>");
cp = result; cp = result;
for (i=0;i<len;++i) { for (i=0;i<len;++i) {
*cp++ = "0123456789ABCDEF"[val[i] >> 4]; *cp++ = "0123456789ABCDEF"[val[i] >> 4];
*cp++ = "0123456789ABCDEF"[val[i] & 0x0f]; *cp++ = "0123456789ABCDEF"[val[i] & 0x0f];
} }
while (ellipses--)
*cp++ = '.';
*cp = 0; *cp = 0;
return result; return result;
} }