From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12116 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: Further wide stdio issues [Was: Re: [PATCH] fix fgetwc when decoding a character that crosses buffer boundary] Date: Mon, 20 Nov 2017 14:28:50 -0500 Message-ID: <20171120192850.GJ1627@brightrain.aerifal.cx> References: <20171118165148.GF15263@port70.net> <20171120014853.GI1627@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="OX2aLCKeO1apYW07" X-Trace: blaine.gmane.org 1511206145 19579 195.159.176.226 (20 Nov 2017 19:29:05 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 20 Nov 2017 19:29:05 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-12132-gllmg-musl=m.gmane.org@lists.openwall.com Mon Nov 20 20:29:01 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1eGrkX-0004bj-Tb for gllmg-musl@m.gmane.org; Mon, 20 Nov 2017 20:28:57 +0100 Original-Received: (qmail 7818 invoked by uid 550); 20 Nov 2017 19:29:03 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 7800 invoked from network); 20 Nov 2017 19:29:02 -0000 Content-Disposition: inline In-Reply-To: <20171120014853.GI1627@brightrain.aerifal.cx> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:12116 Archived-At: --OX2aLCKeO1apYW07 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sun, Nov 19, 2017 at 08:48:53PM -0500, Rich Felker wrote: > On Sat, Nov 18, 2017 at 05:51:48PM +0100, Szabolcs Nagy wrote: > > Update the buffer position according to the bytes consumed into st when > > decoding an incomplete character at the end of the buffer. > > Further related problems: > > 1. fgetws is unable to accurately determine whether fgetwc failed due > to hitting EOF on a clean stream vs hitting EOF in the middle of a > truncated character. The latter is an EILSEQ condition and should > cause fgetws to return a null pointer rather than a line not ending > in newline. > > 2. fgetwc attempts to leave all but the first byte unread on EILSEQ so > that calling fgetwc again will resync, but doesn't do this > consistently when it has to call getc_unlocked to get new bytes > rather than reading from the buffer. > > I think (1) can be fixed in an ugly way by setting errno to something > other than EILSEQ before calling fgetwc, then checking if EILSEQ upon > failure. Patching this; here's a test case (attached). Rich --OX2aLCKeO1apYW07 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="fgetws.c" #include #include #include #include #include int main() { setlocale(LC_CTYPE, ""); int p[2]; pipe(p); write(p[1], "x\340\240xxx", 3); close(p[1]); dup2(p[0], 0); wchar_t buf[100] = {0}; wchar_t *ws = fgetws(buf, 100, stdin); printf("%p [%ls]\n", ws, buf); } --OX2aLCKeO1apYW07--