From bc986b7ff668aa98372fc4e885307339e7ab3f51 Mon Sep 17 00:00:00 2001 From: Takashi Yano Date: Sat, 11 Nov 2023 01:09:47 +0900 Subject: stdio: Fix bugs in commit 3d94e07c49b5 The commit 3d94e07c49b5 has a few bugs which cause testsuite failure in libstdc++. This is due to excess orientation check in __srefill_r() and _ungetc_r(). Further, sscanf() family also calls ssvfscanf() family with fp->_file == -1. This causes undesired orientation set/check for sscanf() family. This patch fixes these problems. Also, as in GLibC, do not set orientation in ungetc, and only set, but do not check orientation in ungetwc. Fixes: 3d94e07c49b5 ("newlib: libc: Fix crash on fprintf to a wide-oriented stream.") Reported-by: Christophe Lyon Reported-by: Joel Sherrill Co-developed-by: Corinna Vinschen Signed-off-by: Takashi Yano Signed-off-by: Corinna Vinschen --- newlib/libc/stdio/vsniprintf.c | 1 + 1 file changed, 1 insertion(+) (limited to 'newlib/libc/stdio/vsniprintf.c') diff --git a/newlib/libc/stdio/vsniprintf.c b/newlib/libc/stdio/vsniprintf.c index e7625ff..a50a0a9 100644 --- a/newlib/libc/stdio/vsniprintf.c +++ b/newlib/libc/stdio/vsniprintf.c @@ -58,6 +58,7 @@ _vsniprintf_r (struct _reent *ptr, return EOF; } f._flags = __SWR | __SSTR; + f._flags2 = 0; f._bf._base = f._p = (unsigned char *) str; f._bf._size = f._w = (size > 0 ? size - 1 : 0); f._file = -1; /* No file. */ -- cgit v1.1