Fix memory corruption in Windows debug library

This patch adjusts the buffer size when reducing the buffer used for printing.
This solves the memory corruption in Windows debug library, and potential
memory corruption in other builds.

llvm-svn: 248588
This commit is contained in:
Jonathan Peyton 2015-09-25 17:23:17 +00:00
parent 0cb8517dc6
commit 7edeef1bbf
2 changed files with 6 additions and 6 deletions

View File

@ -66,13 +66,13 @@ __kmp_affinity_print_mask(char *buf, int buf_len, kmp_affin_mask_t *mask)
}
}
if (i == KMP_CPU_SETSIZE) {
KMP_SNPRINTF(scan, buf_len, "{<empty>}");
KMP_SNPRINTF(scan, end-scan+1, "{<empty>}");
while (*scan != '\0') scan++;
KMP_ASSERT(scan <= end);
return buf;
}
KMP_SNPRINTF(scan, buf_len, "{%ld", (long)i);
KMP_SNPRINTF(scan, end-scan+1, "{%ld", (long)i);
while (*scan != '\0') scan++;
i++;
for (; i < KMP_CPU_SETSIZE; i++) {
@ -89,14 +89,14 @@ __kmp_affinity_print_mask(char *buf, int buf_len, kmp_affin_mask_t *mask)
if (end - scan < 15) {
break;
}
KMP_SNPRINTF(scan, buf_len, ",%-ld", (long)i);
KMP_SNPRINTF(scan, end-scan+1, ",%-ld", (long)i);
while (*scan != '\0') scan++;
}
if (i < KMP_CPU_SETSIZE) {
KMP_SNPRINTF(scan, buf_len, ",...");
KMP_SNPRINTF(scan, end-scan+1, ",...");
while (*scan != '\0') scan++;
}
KMP_SNPRINTF(scan, buf_len, "}");
KMP_SNPRINTF(scan, end-scan+1, "}");
while (*scan != '\0') scan++;
KMP_ASSERT(scan <= end);
return buf;

View File

@ -1178,7 +1178,7 @@ bufdump( kmp_info_t *th, void *buf )
}
for (i = 0; i < l; i++) {
(void) KMP_SNPRINTF(bhex + i * 3, sizeof(bhex), "%02X ", bdump[i]);
(void) KMP_SNPRINTF(bhex + i * 3, sizeof(bhex) - i * 3, "%02X ", bdump[i]);
if (bdump[i] > 0x20 && bdump[i] < 0x7F)
bascii[ i ] = bdump[ i ];
else