提交 f75f489b 编写于 作者: J jsalling

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'
上级 e8662ae1
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册