Re: [PATCH] newlib: libc: Fix bugs in the commit 3d94e07c49b5.

Corinna Vinschen <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
On Nov 10 20:34, Takashi Yano wrote:
> 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(). This patch fixes them.

Oops, _ungetc_r is used from ungetwc as well, that's not good. 
Sorry that I missed that yesterday!

> Fixes: 3d94e07c49b5 ("newlib: libc: Fix crash on fprintf to a wide-oriented stream.")
> Reported-by: Christophe Lyon <[email protected]>
> Reviewed-by:
> Signed-off-by: Takashi Yano <[email protected]>
> ---
>  newlib/libc/stdio/refill.c | 3 ---
>  newlib/libc/stdio/ungetc.c | 8 ++------
>  2 files changed, 2 insertions(+), 9 deletions(-)
> 
> diff --git a/newlib/libc/stdio/refill.c b/newlib/libc/stdio/refill.c
> index c1ef7e120..cd71ed152 100644
> --- a/newlib/libc/stdio/refill.c
> +++ b/newlib/libc/stdio/refill.c
> @@ -43,9 +43,6 @@ __srefill_r (struct _reent * ptr,
>  
>    CHECK_INIT (ptr, fp);
>  
> -  if (ORIENT (fp, -1) != -1)
> -    return EOF;
> -
>    fp->_r = 0;			/* largely a convenience for callers */
>  
>    /* SysV does not make this test; take it out for compatibility */
> diff --git a/newlib/libc/stdio/ungetc.c b/newlib/libc/stdio/ungetc.c
> index 79914af08..5053fd6c4 100644
> --- a/newlib/libc/stdio/ungetc.c
> +++ b/newlib/libc/stdio/ungetc.c
> @@ -125,12 +125,6 @@ _ungetc_r (struct _reent *rptr,
>  
>    _newlib_flockfile_start (fp);
>  
> -  if (ORIENT (fp, -1) != -1)
> -    {
> -      _newlib_flockfile_exit (fp);
> -      return EOF;
> -    }
> -
>    /* After ungetc, we won't be at eof anymore */
>    fp->_flags &= ~__SEOF;
>  
> @@ -213,6 +207,8 @@ int
>  ungetc (int c,
>         register FILE *fp)
>  {
> +  if (ORIENT (fp, -1) != -1)
> +    return EOF;
>    return _ungetc_r (_REENT, c, fp);
>  }
>  #endif /* !_REENT_ONLY */
> -- 
> 2.39.0

Didn't you forget ungetwc?

But then again, I checked GLibC, and there's something weird:

ungetc does not at all set or test the orientation.

ungetwc sets the orientation to 1, but doesn't check it.

Puzzeling.  I wonder about the reasoning behind this.


Corinna
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.