Revert "Don't overread or write memory returned by _DTOA_R"
This reverts commit efaef1bba2
.
This commit is contained in:
parent
5ca286666a
commit
14ea06212b
|
@ -1631,18 +1631,12 @@ wcvt(struct _reent *data, _PRINTF_FLOAT_TYPE value, int ndigits, int flags,
|
||||||
|
|
||||||
{
|
{
|
||||||
char *digits, *bp, *rve;
|
char *digits, *bp, *rve;
|
||||||
|
#ifndef _MB_CAPABLE
|
||||||
int i;
|
int i;
|
||||||
|
#endif
|
||||||
|
|
||||||
digits = _DTOA_R (data, value, mode, ndigits, decpt, &dsgn, &rve);
|
digits = _DTOA_R (data, value, mode, ndigits, decpt, &dsgn, &rve);
|
||||||
|
|
||||||
#ifdef _MB_CAPABLE
|
|
||||||
_mbsnrtowcs_r (data, buf, (const char **) &digits, rve - digits,
|
|
||||||
len, NULL);
|
|
||||||
#else
|
|
||||||
for (i = 0; i < rve - digits && i < len; ++i)
|
|
||||||
buf[i] = (wchar_t) digits[i];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if ((ch != L'g' && ch != L'G') || flags & ALT) { /* Print trailing zeros */
|
if ((ch != L'g' && ch != L'G') || flags & ALT) { /* Print trailing zeros */
|
||||||
bp = digits + ndigits;
|
bp = digits + ndigits;
|
||||||
if (ch == L'f' || ch == L'F') {
|
if (ch == L'f' || ch == L'F') {
|
||||||
|
@ -1652,13 +1646,18 @@ wcvt(struct _reent *data, _PRINTF_FLOAT_TYPE value, int ndigits, int flags,
|
||||||
}
|
}
|
||||||
if (value == 0) /* kludge for __dtoa irregularity */
|
if (value == 0) /* kludge for __dtoa irregularity */
|
||||||
rve = bp;
|
rve = bp;
|
||||||
|
while (rve < bp)
|
||||||
for (i = rve - digits; i < bp - digits && i < len; ++i)
|
*rve++ = '0';
|
||||||
buf[i] = L'0';
|
|
||||||
|
|
||||||
rve = rve > bp ? rve : bp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*length = rve - digits; /* full length of the string */
|
*length = rve - digits; /* full length of the string */
|
||||||
|
#ifdef _MB_CAPABLE
|
||||||
|
_mbsnrtowcs_r (data, buf, (const char **) &digits, *length,
|
||||||
|
len, NULL);
|
||||||
|
#else
|
||||||
|
for (i = 0; i < *length && i < len; ++i)
|
||||||
|
buf[i] = (wchar_t) digits[i];
|
||||||
|
#endif
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue