Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20191018131149.GX16318@brightrain.aerifal.cx>
Date: Fri, 18 Oct 2019 09:11:49 -0400
From: Rich Felker <dalias@...c.org>
To: musl@...ts.openwall.com
Subject: Re: [PATCH 1/1] ungetc: Cast to unsigned char before push
 back to stream

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 <wangjianjian3@...wei.com>
> 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 <wangjianjian3@...wei.com>
> ---
>  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

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.