From e2d5e1c6324302edbbeb46defbb3a09ff8dafd89 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Mon, 1 Sep 2014 16:44:18 -0400 Subject: [PATCH] Fixed printability of largest negative value (Thanks SigmaPic!) --- src/unity.c | 12 +++++++++--- test/tests/testunity.c | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/unity.c b/src/unity.c index 6766713..0881e2e 100644 --- a/src/unity.c +++ b/src/unity.c @@ -125,12 +125,18 @@ void UnityPrintNumber(const _U_SINT number_to_print) { _U_SINT divisor = 1; _U_SINT next_divisor; - _U_SINT number = number_to_print; - if (number < 0) + _U_UINT number; + + if (number_to_print < 0) { UNITY_OUTPUT_CHAR('-'); - number = -number; + number = -number_to_print; + } + else + { + number = number_to_print; + } // figure out initial divisor diff --git a/test/tests/testunity.c b/test/tests/testunity.c index 2ee18fb..a701c92 100755 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -218,7 +218,7 @@ void testNotEqualInt16s(void) void testNotEqualInt32s(void) { EXPECT_ABORT_BEGIN - TEST_ASSERT_EQUAL_INT32(-2147483647, -2147483646); + TEST_ASSERT_EQUAL_INT32(-2147483647, -2147483648); //use largest 32 bit negative to test printability VERIFY_FAILS_END }