diff options
author | Rich Felker <dalias@aerifal.cx> | 2015-06-13 05:17:16 +0000 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2015-06-13 05:17:16 +0000 |
commit | 536c6d5a4205e2a3f161f2983ce1e0ac3082187d (patch) | |
tree | a45cf47d93d62585cd417b83bd49100edf419222 /src/stdio/ungetwc.c | |
parent | f8f565df467c13248104223f99abf7f37cef7584 (diff) | |
download | musl-536c6d5a4205e2a3f161f2983ce1e0ac3082187d.tar.gz musl-536c6d5a4205e2a3f161f2983ce1e0ac3082187d.tar.bz2 musl-536c6d5a4205e2a3f161f2983ce1e0ac3082187d.tar.xz musl-536c6d5a4205e2a3f161f2983ce1e0ac3082187d.zip |
fix idiom for setting stdio stream orientation to wide
the old idiom, f->mode |= f->mode+1, was adapted from the idiom for
setting byte orientation, f->mode |= f->mode-1, but the adaptation was
incorrect. unless the stream was alreasdy set byte-oriented, this code
incremented f->mode each time it was executed, which would eventually
lead to overflow. it could be fixed by changing it to f->mode |= 1,
but upcoming changes will require slightly more work at the time of
wide orientation, so it makes sense to just call fwide. as an
optimization in the single-character functions, fwide is only called
if the stream is not already wide-oriented.
Diffstat (limited to 'src/stdio/ungetwc.c')
-rw-r--r-- | src/stdio/ungetwc.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/stdio/ungetwc.c b/src/stdio/ungetwc.c index 394f92ac..d4c7de39 100644 --- a/src/stdio/ungetwc.c +++ b/src/stdio/ungetwc.c @@ -11,7 +11,7 @@ wint_t ungetwc(wint_t c, FILE *f) FLOCK(f); - f->mode |= f->mode+1; + if (f->mode <= 0) fwide(f, 1); if (!f->rpos) __toread(f); if (!f->rpos || f->rpos < f->buf - UNGET + l || c == WEOF || |