Used sizeof() operator for pointer increments and substituted sizeof() operator for the unsigned int mask calculation to "UNITY_INT_WIDTH / 8" in function "UnityAssertEqualIntArray".

This commit is contained in:
Fabian Zahn
2019-04-06 11:55:24 +02:00
parent 8507757c6a
commit d01e32299e
3 changed files with 33 additions and 20 deletions

View File

@ -1,6 +1,6 @@
/* ========================================================================= /* =========================================================================
Unity Project - A Test Framework for C Unity Project - A Test Framework for C
Copyright (c) 2007-14 Mike Karlesky, Mark VanderVoord, Greg Williams Copyright (c) 2007-19 Mike Karlesky, Mark VanderVoord, Greg Williams
[Released under MIT License. Please refer to license.txt for details] [Released under MIT License. Please refer to license.txt for details]
============================================================================ */ ============================================================================ */
@ -693,7 +693,8 @@ static int UnityIsOneArrayNull(UNITY_INTERNAL_PTR expected,
const UNITY_LINE_TYPE lineNumber, const UNITY_LINE_TYPE lineNumber,
const char* msg) const char* msg)
{ {
if (expected == actual) return 0; /* Both are NULL or same pointer */ /* Both are NULL or same pointer */
if (expected == actual) { return 0; }
/* print and return true if just expected is NULL */ /* print and return true if just expected is NULL */
if (expected == NULL) if (expected == NULL)
@ -819,6 +820,7 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected,
{ {
UNITY_UINT32 elements = num_elements; UNITY_UINT32 elements = num_elements;
unsigned int length = style & 0xF; unsigned int length = style & 0xF;
unsigned int increment = 0;
RETURN_IF_FAIL_OR_IGNORE; RETURN_IF_FAIL_OR_IGNORE;
@ -841,32 +843,41 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected,
{ {
UNITY_INT expect_val; UNITY_INT expect_val;
UNITY_INT actual_val; UNITY_INT actual_val;
switch (length) switch (length)
{ {
case 1: case 1:
expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT8*)expected; expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT8*)expected;
actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT8*)actual; actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT8*)actual;
increment = sizeof(UNITY_INT8);
break; break;
case 2: case 2:
expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT16*)expected; expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT16*)expected;
actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT16*)actual; actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT16*)actual;
increment = sizeof(UNITY_INT16);
break; break;
#ifdef UNITY_SUPPORT_64 #ifdef UNITY_SUPPORT_64
case 8: case 8:
expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT64*)expected; expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT64*)expected;
actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT64*)actual; actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT64*)actual;
increment = sizeof(UNITY_INT64);
break; break;
#endif #endif
default: /* length 4 bytes */
default: /* default is length 4 bytes */
case 4:
expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT32*)expected; expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT32*)expected;
actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT32*)actual; actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT32*)actual;
increment = sizeof(UNITY_INT32);
length = 4; length = 4;
break; break;
} }
if (expect_val != actual_val) if (expect_val != actual_val)
{ {
if ((style & UNITY_DISPLAY_RANGE_UINT) && (length < sizeof(expect_val))) if ((style & UNITY_DISPLAY_RANGE_UINT) && (length < (UNITY_INT_WIDTH / 8)))
{ /* For UINT, remove sign extension (padding 1's) from signed type casts above */ { /* For UINT, remove sign extension (padding 1's) from signed type casts above */
UNITY_INT mask = 1; UNITY_INT mask = 1;
mask = (mask << 8 * length) - 1; mask = (mask << 8 * length) - 1;
@ -883,11 +894,12 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected,
UnityAddMsgIfSpecified(msg); UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL; UNITY_FAIL_AND_BAIL;
} }
/* Walk through array by incrementing the pointers */
if (flags == UNITY_ARRAY_TO_ARRAY) if (flags == UNITY_ARRAY_TO_ARRAY)
{ {
expected = (UNITY_INTERNAL_PTR)(length + (const char*)expected); expected = (UNITY_INTERNAL_PTR)((const char*)expected + increment);
} }
actual = (UNITY_INTERNAL_PTR)(length + (const char*)actual); actual = (UNITY_INTERNAL_PTR)((const char*)actual + increment);
} }
} }
@ -1504,6 +1516,7 @@ UNITY_INTERNAL_PTR UnityNumToPtr(const UNITY_INT num, const UNITY_UINT8 size)
UnityQuickCompare.i64 = (UNITY_INT64)num; UnityQuickCompare.i64 = (UNITY_INT64)num;
return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i64); return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i64);
#endif #endif
default: /* 4 bytes */ default: /* 4 bytes */
UnityQuickCompare.i32 = (UNITY_INT32)num; UnityQuickCompare.i32 = (UNITY_INT32)num;
return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i32); return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i32);

View File

@ -1,6 +1,6 @@
/* ========================================== /* ==========================================
Unity Project - A Test Framework for C Unity Project - A Test Framework for C
Copyright (c) 2007-14 Mike Karlesky, Mark VanderVoord, Greg Williams Copyright (c) 2007-19 Mike Karlesky, Mark VanderVoord, Greg Williams
[Released under MIT License. Please refer to license.txt for details] [Released under MIT License. Please refer to license.txt for details]
========================================== */ ========================================== */

View File

@ -1,6 +1,6 @@
/* ========================================== /* ==========================================
Unity Project - A Test Framework for C Unity Project - A Test Framework for C
Copyright (c) 2007-14 Mike Karlesky, Mark VanderVoord, Greg Williams Copyright (c) 2007-19 Mike Karlesky, Mark VanderVoord, Greg Williams
[Released under MIT License. Please refer to license.txt for details] [Released under MIT License. Please refer to license.txt for details]
========================================== */ ========================================== */