Fix undefined behavior when printing INT_MIN/INT64_MIN.

Negating the most-negative signed integer results in overflow, which
is undefined behavior.  Fix this by casting to an unsigned type first
(unsigned overflow is well-defined as it uses modular arithmetic).
This commit is contained in:
John Lindgren
2018-11-28 14:40:40 -05:00
parent 58be52f088
commit 8a77f48634

View File

@@ -183,7 +183,7 @@ void UnityPrintNumber(const UNITY_INT number_to_print)
{
/* A negative number, including MIN negative */
UNITY_OUTPUT_CHAR('-');
number = (UNITY_UINT)(-number_to_print);
number = -number;
}
UnityPrintNumberUnsigned(number);
}