mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-12-18 06:18:37 +08:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user