projects
/
musl
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
math: avoid runtime conversions of floating-point constants
[musl]
/
src
/
stdio
/
vfprintf.c
diff --git
a/src/stdio/vfprintf.c
b/src/stdio/vfprintf.c
index
15356f5
..
9b961e7
100644
(file)
--- a/
src/stdio/vfprintf.c
+++ b/
src/stdio/vfprintf.c
@@
-5,6
+5,7
@@
#include <string.h>
#include <stdarg.h>
#include <stddef.h>
#include <string.h>
#include <stdarg.h>
#include <stddef.h>
+#include <stdlib.h>
#include <wchar.h>
#include <inttypes.h>
#include <math.h>
#include <wchar.h>
#include <inttypes.h>
#include <math.h>
@@
-220,6
+221,7
@@
static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t)
else re=LDBL_MANT_DIG/4-1-p;
if (re) {
else re=LDBL_MANT_DIG/4-1-p;
if (re) {
+ round *= 1<<(LDBL_MANT_DIG%4);
while (re--) round*=16;
if (*prefix=='-') {
y=-y;
while (re--) round*=16;
if (*prefix=='-') {
y=-y;
@@
-559,7
+561,7
@@
static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg,
if (0) {
case 'o':
a = fmt_o(arg.i, z);
if (0) {
case 'o':
a = fmt_o(arg.i, z);
- if ((fl&ALT_FORM) && p<z-a+1) p
refix+=5, pl=
1;
+ if ((fl&ALT_FORM) && p<z-a+1) p
=z-a+
1;
} if (0) {
case 'd': case 'i':
pl=1;
} if (0) {
case 'd': case 'i':
pl=1;
@@
-574,7
+576,7
@@
static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg,
a = fmt_u(arg.i, z);
}
if (xp && p<0) goto overflow;
a = fmt_u(arg.i, z);
}
if (xp && p<0) goto overflow;
- if (
p>=0
) fl &= ~ZERO_PAD;
+ if (
xp
) fl &= ~ZERO_PAD;
if (!arg.i && !p) {
a=z;
break;
if (!arg.i && !p) {
a=z;
break;
@@
-673,11
+675,12
@@
int vfprintf(FILE *restrict f, const char *restrict fmt, va_list ap)
if (f->mode < 1) f->flags &= ~F_ERR;
if (!f->buf_size) {
saved_buf = f->buf;
if (f->mode < 1) f->flags &= ~F_ERR;
if (!f->buf_size) {
saved_buf = f->buf;
- f->
wpos = f->wbase = f->
buf = internal_buf;
+ f->buf = internal_buf;
f->buf_size = sizeof internal_buf;
f->buf_size = sizeof internal_buf;
- f->w
end = internal_buf + sizeof internal_buf
;
+ f->w
pos = f->wbase = f->wend = 0
;
}
}
- ret = printf_core(f, fmt, &ap2, nl_arg, nl_type);
+ if (!f->wend && __towrite(f)) ret = -1;
+ else ret = printf_core(f, fmt, &ap2, nl_arg, nl_type);
if (saved_buf) {
f->write(f, 0, 0);
if (!f->wpos) ret = -1;
if (saved_buf) {
f->write(f, 0, 0);
if (!f->wpos) ret = -1;