From f75f489b6effb8a396df3cc448a7bd1ec9cc90e6 Mon Sep 17 00:00:00 2001 From: jsalling Date: Mon, 14 Dec 2015 16:40:07 -0600 Subject: [PATCH] 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' --- extras/fixture/src/unity_fixture.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/extras/fixture/src/unity_fixture.c b/extras/fixture/src/unity_fixture.c index e781256..57009dc 100644 --- a/extras/fixture/src/unity_fixture.c +++ b/extras/fixture/src/unity_fixture.c @@ -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; }