You need to sign in or sign up before continuing.
未验证 提交 8e0f54d2 编写于 作者: M Mark VanderVoord 提交者: GitHub

Merge pull request #375 from jlindgren90/int-min-printing

Fix undefined behavior when printing INT_MIN/INT64_MIN. (Thanks @jlindgren90 !)
...@@ -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);
} }
...@@ -1019,22 +1019,22 @@ void UnityAssertNumbersWithin(const UNITY_UINT delta, ...@@ -1019,22 +1019,22 @@ void UnityAssertNumbersWithin(const UNITY_UINT delta,
{ {
if (actual > expected) if (actual > expected)
{ {
Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(actual - expected) > delta); Unity.CurrentTestFailed = (((UNITY_UINT)actual - (UNITY_UINT)expected) > delta);
} }
else else
{ {
Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(expected - actual) > delta); Unity.CurrentTestFailed = (((UNITY_UINT)expected - (UNITY_UINT)actual) > delta);
} }
} }
else else
{ {
if ((UNITY_UINT)actual > (UNITY_UINT)expected) if ((UNITY_UINT)actual > (UNITY_UINT)expected)
{ {
Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(actual - expected) > delta); Unity.CurrentTestFailed = (((UNITY_UINT)actual - (UNITY_UINT)expected) > delta);
} }
else else
{ {
Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(expected - actual) > delta); Unity.CurrentTestFailed = (((UNITY_UINT)expected - (UNITY_UINT)actual) > delta);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册