Author: tkreuzer
Date: Mon Jan 3 10:33:58 2011
New Revision: 50274
URL:
http://svn.reactos.org/svn/reactos?rev=50274&view=rev
Log:
[CRT]
Fix several bugs in new printf implementation.
Modified:
trunk/reactos/lib/sdk/crt/printf/streamout.c
Modified: trunk/reactos/lib/sdk/crt/printf/streamout.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/printf/streamo…
==============================================================================
--- trunk/reactos/lib/sdk/crt/printf/streamout.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/printf/streamout.c [iso-8859-1] Mon Jan 3 10:33:58 2011
@@ -108,7 +108,17 @@
case _T('G'):
digits = digits_u;
case _T('g'):
+ if (precision > 0) precision--;
if (exponent < -4 || exponent >= precision) goto case_e;
+
+ /* Skip trailing 0s */
+ val64 = (__int64)(fpval * pow(10., precision) + 0.5);
+ while (precision && val64 % 10 == 0)
+ {
+ precision--;
+ val64 /= 10;
+ }
+
break;
case _T('E'):
@@ -128,7 +138,7 @@
}
/* Sign for the exponent */
- *--(*string) = exponent > 0 ? _T('+') : _T('-');
+ *--(*string) = exponent >= 0 ? _T('+') : _T('-');
/* Add 'e' or 'E' separator */
*--(*string) = digits[0xe];
@@ -173,9 +183,8 @@
}
else
{
- fpval *= pow(10., precision);
- val64 = (__int64)(fpval + 0.5);
-
+ /* Digits after the decimal point */
+ val64 = (__int64)(fpval * pow(10., precision) + 0.5);
while (num_digits-- > 0)
{
*--(*string) = digits[val64 % 10];
@@ -183,7 +192,8 @@
}
}
- *--(*string) = _T('.');
+ if (precision > 0 || flags & FLAG_SPECIAL)
+ *--(*string) = _T('.');
/* Digits before the decimal point */
do
@@ -372,6 +382,7 @@
if (chr == _T('h')) flags |= FLAG_SHORT;
else if (chr == _T('w')) flags |= FLAG_WIDECHAR;
else if (chr == _T('L')) flags |= 0; // FIXME: long double
+ else if (chr == _T('F')) flags |= 0; // FIXME: what is that?
else if (chr == _T('l'))
{
flags |= FLAG_LONG;
@@ -483,6 +494,7 @@
else
len = strlen((char*)string);
if (precision >= 0 && len > precision) len = precision;
+ precision = 0;
break;
case _T('G'):
@@ -521,9 +533,12 @@
case _T('o'):
base = 8;
- if (flags & FLAG_SPECIAL) prefix = _T("0");
+ if (flags & FLAG_SPECIAL)
+ {
+ prefix = _T("0");
+ if (precision > 0) precision--;
+ }
goto case_unsigned;
- /* Fall through */
case _T('p'):
precision = 2 * sizeof(void*);