Переглянути джерело

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. (!)
Nick Mathewson 11 роки тому
батько
коміт
9c9e07963d
1 змінених файлів з 8 додано та 1 видалено
  1. 8 1
      src/ext/tinytest.c

+ 8 - 1
src/ext/tinytest.c

@@ -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;
 }