1
0
mirror of https://github.com/ThrowTheSwitch/Unity.git synced 2026-01-28 10:44:26 +01:00

Check for writes to guard space on malloc'd buffers in Fixture

There was already some space reserved as a guard, added check for writes
 before the beginning of the buffer. Did not change the 'overrun' message.
 Underrun buffer writes are likely to be a more rare case.
This commit is contained in:
jsalling
2016-02-05 18:56:44 -06:00
parent 7943c766b9
commit 189085d03a
3 changed files with 46 additions and 2 deletions

View File

@@ -166,7 +166,7 @@ static unsigned int heap_index;
typedef struct GuardBytes
{
size_t size;
char guard_space[4];
size_t guard_space;
} Guard;
@@ -202,6 +202,7 @@ void* unity_malloc(size_t size)
if (guard == NULL) return NULL;
malloc_count++;
guard->size = size;
guard->guard_space = 0;
mem = (char*)&(guard[1]);
memcpy(&mem[size], end, sizeof(end));
@@ -214,7 +215,7 @@ static int isOverrun(void* mem)
char* memAsChar = (char*)mem;
guard--;
return strcmp(&memAsChar[guard->size], end) != 0;
return guard->guard_space != 0 || strcmp(&memAsChar[guard->size], end) != 0;
}
static void release_memory(void* mem)