From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14824 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 09:11:49 -0400 Message-ID: <20191018131149.GX16318@brightrain.aerifal.cx> References: 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="240712"; 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-14840-gllmg-musl=m.gmane.org@lists.openwall.com Fri Oct 18 15:12:05 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 1iLS33-0010Xz-GS for gllmg-musl@m.gmane.org; Fri, 18 Oct 2019 15:12:05 +0200 Original-Received: (qmail 7210 invoked by uid 550); 18 Oct 2019 13:12: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 7192 invoked from network); 18 Oct 2019 13:12:02 -0000 Content-Disposition: inline In-Reply-To: Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:14824 Archived-At: 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. Rich