Get rid of magic numbers and strlen call for 'end' string in Fixture

Using sizeof() instead of constant 4, makes code less fragile to change
 Change name of 'guard' in Guard struct to 'guard_space'
This commit is contained in:
jsalling
2015-12-14 16:40:07 -06:00
parent e8662ae1cc
commit f75f489b6e

View File

@ -179,11 +179,11 @@ void UnityMalloc_MakeMallocFailAfterCount(int countdown)
typedef struct GuardBytes
{
size_t size;
char guard[sizeof(size_t)];
char guard_space[4];
} Guard;
static const char * end = "END";
static const char end[] = "END";
void * unity_malloc(size_t size)
{
@ -199,10 +199,10 @@ void * unity_malloc(size_t size)
malloc_count++;
guard = (Guard*)UNITY_FIXTURE_MALLOC(size + sizeof(Guard) + 4);
guard = (Guard*)UNITY_FIXTURE_MALLOC(size + sizeof(Guard) + sizeof(end));
guard->size = size;
mem = (char*)&(guard[1]);
memcpy(&mem[size], end, strlen(end) + 1);
memcpy(&mem[size], end, sizeof(end));
return (void*)mem;
}