mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-07-15 00:52:46 +08:00
tightened up pointer handling in UnityAssertEqualMemoryArray to satisfy stricter compilers
git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@46 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
This commit is contained in:
12
src/unity.c
12
src/unity.c
@ -539,6 +539,8 @@ void UnityAssertEqualMemoryArray(const void* expected,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber)
|
||||
{
|
||||
unsigned char* expected_ptr = (unsigned char*)expected;
|
||||
unsigned char* actual_ptr = (unsigned char*)actual;
|
||||
unsigned long elements = num_elements;
|
||||
if ((elements == 0) || (length == 0))
|
||||
{
|
||||
@ -556,22 +558,22 @@ void UnityAssertEqualMemoryArray(const void* expected,
|
||||
}
|
||||
|
||||
// if both pointers not null compare the memory
|
||||
if (expected && actual)
|
||||
if (expected_ptr && actual_ptr)
|
||||
{
|
||||
while (elements--)
|
||||
{
|
||||
if (memcmp(expected, actual, length) != 0)
|
||||
if (memcmp((const void*)expected_ptr, (const void*)actual_ptr, length) != 0)
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
break;
|
||||
}
|
||||
expected += length;
|
||||
actual += length;
|
||||
expected_ptr += length;
|
||||
actual_ptr += length;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // handle case of one pointers being null (if both null, test should pass)
|
||||
if (expected != actual)
|
||||
if (expected_ptr != actual_ptr)
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
}
|
||||
|
10
src/unity.h
10
src/unity.h
@ -141,11 +141,11 @@ void UnityAssertEqualMemory(const void* expected,
|
||||
const unsigned short lineNumber );
|
||||
|
||||
void UnityAssertEqualMemoryArray(const void* expected,
|
||||
const void* actual,
|
||||
unsigned long length,
|
||||
unsigned long num_elements,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber );
|
||||
const void* actual,
|
||||
unsigned long length,
|
||||
unsigned long num_elements,
|
||||
const char* msg,
|
||||
const unsigned short lineNumber );
|
||||
|
||||
void UnityAssertFloatsWithin(const float delta,
|
||||
const float expected,
|
||||
|
Reference in New Issue
Block a user