Handle allocation quirk on non-null-returning allocators

Some allocators return a non-null pointer when calling *alloc with
zero size, that will segfault upon access. Check for the size parameter
before allocating anything to ensure that the breakpoint and trace
fields will stay null when size >> 3 or size >> 1 is zero.
This commit is contained in:
Koakuma 2020-11-21 12:10:15 +07:00 committed by Rafael Kitover
parent edc34942a8
commit 4fc3b4297d
1 changed files with 11 additions and 7 deletions

View File

@ -1443,19 +1443,23 @@ void SetMapMasks()
#ifdef BKPT_SUPPORT
for (int i = 0; i < 16; i++) {
map[i].size = map[i].mask + 1;
if (map[i].size > 0) {
map[i].trace = (uint8_t*)calloc(map[i].size >> 3, sizeof(uint8_t));
map[i].trace = NULL;
map[i].breakPoints = NULL;
if ((map[i].size >> 1) > 0) {
map[i].breakPoints = (uint8_t*)calloc(map[i].size >> 1, sizeof(uint8_t));
if (map[i].trace == NULL || map[i].breakPoints == NULL) {
if (map[i].breakPoints == NULL) {
systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"),
"TRACE");
}
} else {
map[i].trace = NULL;
map[i].breakPoints = NULL;
}
if ((map[i].size >> 3) > 0) {
map[i].trace = (uint8_t*)calloc(map[i].size >> 3, sizeof(uint8_t));
if (map[i].trace == NULL) {
systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"),
"TRACE");
}
}
}
clearBreakRegList();