提交 8a77f486 编写于 作者: J John Lindgren

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).
上级 58be52f0
...@@ -183,7 +183,7 @@ void UnityPrintNumber(const UNITY_INT number_to_print) ...@@ -183,7 +183,7 @@ void UnityPrintNumber(const UNITY_INT number_to_print)
{ {
/* A negative number, including MIN negative */ /* A negative number, including MIN negative */
UNITY_OUTPUT_CHAR('-'); UNITY_OUTPUT_CHAR('-');
number = (UNITY_UINT)(-number_to_print); number = -number;
} }
UnityPrintNumberUnsigned(number); UnityPrintNumberUnsigned(number);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册