From 480335061c1afbf7e5ac796e919f85d91a119a72 Mon Sep 17 00:00:00 2001 From: jsalling Date: Thu, 12 Jan 2017 22:18:14 -0600 Subject: [PATCH 1/2] No print masking of integers, bounds on hex printing --- src/unity.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/src/unity.c b/src/unity.c index 4c00f7e..9e9ebb7 100644 --- a/src/unity.c +++ b/src/unity.c @@ -52,21 +52,6 @@ static const char UnityStrResultsIgnored[] = " Ignored "; static const char UnityStrDetail1Name[] = UNITY_DETAIL1_NAME " "; static const char UnityStrDetail2Name[] = " " UNITY_DETAIL2_NAME " "; -/* compiler-generic print formatting masks */ -static const UNITY_UINT UnitySizeMask[] = -{ - 255u, /* 0xFF */ - 65535u, /* 0xFFFF */ - 65535u, - 4294967295u, /* 0xFFFFFFFF */ - 4294967295u, - 4294967295u, - 4294967295u -#ifdef UNITY_SUPPORT_64 - ,0xFFFFFFFFFFFFFFFF -#endif -}; - /*----------------------------------------------- * Pretty Printers & Test Result Output Handlers *-----------------------------------------------*/ @@ -155,13 +140,13 @@ void UnityPrintNumberByStyle(const UNITY_INT number, const UNITY_DISPLAY_STYLE_T } else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT) { - UnityPrintNumberUnsigned( (UNITY_UINT)number & UnitySizeMask[((UNITY_UINT)style & (UNITY_UINT)0x0F) - 1] ); + UnityPrintNumberUnsigned((UNITY_UINT)number); } else { UNITY_OUTPUT_CHAR('0'); UNITY_OUTPUT_CHAR('x'); - UnityPrintNumberHex((UNITY_UINT)number, (char)((style & 0x000F) << 1)); + UnityPrintNumberHex((UNITY_UINT)number, (char)((style & 0xF) * 2)); } } @@ -203,19 +188,21 @@ void UnityPrintNumberUnsigned(const UNITY_UINT number) /*-----------------------------------------------*/ void UnityPrintNumberHex(const UNITY_UINT number, const char nibbles_to_print) { - UNITY_UINT nibble; + int nibble; char nibbles = nibbles_to_print; + if ((unsigned)nibbles > 2 * sizeof number) nibbles = 2 * sizeof number; while (nibbles > 0) { - nibble = (number >> (--nibbles << 2)) & 0x0000000F; + nibbles--; + nibble = (number >> (nibbles * 4)) & 0x0F; if (nibble <= 9) { - UNITY_OUTPUT_CHAR((char)('0' + nibble)); + UNITY_OUTPUT_CHAR('0' + nibble); } else { - UNITY_OUTPUT_CHAR((char)('A' - 10 + nibble)); + UNITY_OUTPUT_CHAR('A' - 10 + nibble); } } } From 437c474b0771de405a18815135d7ea3d93072329 Mon Sep 17 00:00:00 2001 From: jsalling Date: Tue, 17 Jan 2017 21:26:15 -0600 Subject: [PATCH 2/2] Put back (char) casts, better formatting --- src/unity.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/unity.c b/src/unity.c index 9e9ebb7..c1bbeec 100644 --- a/src/unity.c +++ b/src/unity.c @@ -190,7 +190,8 @@ void UnityPrintNumberHex(const UNITY_UINT number, const char nibbles_to_print) { int nibble; char nibbles = nibbles_to_print; - if ((unsigned)nibbles > 2 * sizeof number) nibbles = 2 * sizeof number; + if ((unsigned)nibbles > (2 * sizeof(number))) + nibbles = 2 * sizeof(number); while (nibbles > 0) { @@ -198,11 +199,11 @@ void UnityPrintNumberHex(const UNITY_UINT number, const char nibbles_to_print) nibble = (number >> (nibbles * 4)) & 0x0F; if (nibble <= 9) { - UNITY_OUTPUT_CHAR('0' + nibble); + UNITY_OUTPUT_CHAR((char)('0' + nibble)); } else { - UNITY_OUTPUT_CHAR('A' - 10 + nibble); + UNITY_OUTPUT_CHAR((char)('A' - 10 + nibble)); } } }