From: Rich Felker Date: Sat, 6 Jun 2015 18:11:17 +0000 (+0000) Subject: remove invalid skip of locking in ungetwc X-Git-Tag: v1.1.11~58 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=7e816a6487932cbb3cb71d94b609e50e81f4e5bf;p=oweals%2Fmusl.git remove invalid skip of locking in ungetwc aside from being invalid, the early check only optimized the error case, and likely pessimized the common case by separating the two branches on isascii(c) at opposite ends of the function. --- diff --git a/src/stdio/ungetwc.c b/src/stdio/ungetwc.c index 913f7168..0a4cd7a1 100644 --- a/src/stdio/ungetwc.c +++ b/src/stdio/ungetwc.c @@ -11,18 +11,15 @@ wint_t ungetwc(wint_t c, FILE *f) if (c == WEOF) return c; - /* Try conversion early so we can fail without locking if invalid */ - if (!isascii(c) && (l = wctomb((void *)mbc, c)) < 0) - return WEOF; - FLOCK(f); f->mode |= f->mode+1; if (!f->rpos) __toread(f); - if (!f->rpos || f->rpos < f->buf - UNGET + l) { + if (!f->rpos || f->rpos < f->buf - UNGET + l || + (!isascii(c) && (l = wctomb((void *)mbc, c)) < 0)) { FUNLOCK(f); - return EOF; + return WEOF; } if (isascii(c)) *--f->rpos = c;