提交 67a37a4d 编写于 作者: J jsalling

Refactor UnityPrintNumber(), remove unreachable code

 Remove what looks like an overflow check. 'divisor' cannot overflow
  since it is the same type as 'number' and cannot be greater.
上级 0247e34b
......@@ -164,12 +164,9 @@ void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T s
}
//-----------------------------------------------
/// basically do an itoa using as little ram as possible
void UnityPrintNumber(const _U_SINT number_to_print)
{
_U_UINT divisor = 1;
_U_UINT next_divisor;
_U_UINT number;
_U_UINT number = (_U_UINT)number_to_print;
if (number_to_print < 0)
{
......@@ -177,29 +174,7 @@ void UnityPrintNumber(const _U_SINT number_to_print)
UNITY_OUTPUT_CHAR('-');
number = (_U_UINT)(-number_to_print);
}
else
{
//Non-negative number
number = (_U_UINT)number_to_print;
}
// figure out initial divisor
while (number / divisor > 9)
{
next_divisor = divisor * 10;
if (next_divisor > divisor)
divisor = next_divisor;
else
break;
}
// now mod and print, then divide divisor
do
{
UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
divisor /= 10;
}
while (divisor > 0);
UnityPrintNumberUnsigned(number);
}
//-----------------------------------------------
......@@ -207,16 +182,11 @@ void UnityPrintNumber(const _U_SINT number_to_print)
void UnityPrintNumberUnsigned(const _U_UINT number)
{
_U_UINT divisor = 1;
_U_UINT next_divisor;
// figure out initial divisor
while (number / divisor > 9)
{
next_divisor = divisor * 10;
if (next_divisor > divisor)
divisor = next_divisor;
else
break;
divisor *= 10;
}
// now mod and print, then divide divisor
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册