From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14829 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH 1/1] ungetc: Cast to unsigned char before push back to stream Date: Fri, 18 Oct 2019 21:18:29 -0400 Message-ID: <20191019011829.GZ16318@brightrain.aerifal.cx> References: <20191018131149.GX16318@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="85956"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-14845-gllmg-musl=m.gmane.org@lists.openwall.com Sat Oct 19 03:18:49 2019 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.89) (envelope-from ) id 1iLdOH-000MDS-Dw for gllmg-musl@m.gmane.org; Sat, 19 Oct 2019 03:18:45 +0200 Original-Received: (qmail 20071 invoked by uid 550); 19 Oct 2019 01:18:42 -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 20053 invoked from network); 19 Oct 2019 01:18:42 -0000 Content-Disposition: inline In-Reply-To: <20191018131149.GX16318@brightrain.aerifal.cx> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:14829 Archived-At: On Fri, Oct 18, 2019 at 09:11:49AM -0400, Rich Felker wrote: > On Fri, Oct 18, 2019 at 12:35:45PM +0000, wangjianjian (C) wrote: > > >From 4d24e6fee85ed878dc632dd29aabeb7c7454952e Mon Sep 17 00:00:00 2001 > > From: Wang Jianjian > > Date: Fri, 18 Oct 2019 20:28:29 +0800 > > Subject: [PATCH 1/1] ungetc: Cast to unsigned char before push back to stream > > > > Per Posix standard, casting to unsigned char is need before returning C > > and pushing C back to stream. > > > > Signed-off-by: Wang Jianjian > > --- > > src/stdio/ungetc.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/src/stdio/ungetc.c b/src/stdio/ungetc.c > > index 180673a4..9733091a 100644 > > --- a/src/stdio/ungetc.c > > +++ b/src/stdio/ungetc.c > > @@ -12,9 +12,9 @@ int ungetc(int c, FILE *f) > > return EOF; > > } > > > > - *--f->rpos = c; > > + *--f->rpos = (unsigned char)c; > > This line does not change anything. > > > f->flags &= ~F_EOF; > > > > FUNLOCK(f); > > - return c; > > + return (unsigned char)c; > > } > > -- > > 2.17.1 > > I believe this is actually a functional change, and a needed one for > conformance (to ISO C, not specific to POSIX). The issue it seems to > solve, which is what the change needs to be documented as, is the > return value when a negative value not equal to EOF is passed to > ungetc. In this case, the right value is already pushed back, but the > function wrongly returns the original negative value passed in rather > than the value that was pushed back. Committing simplified version with just the second change. Thanks for catching this. Rich