mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-10-18 12:53:23 +08:00
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:
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user