[PATCH v2] libio: Fix stream orientation when using fread [BZ #22796]

Andreas Schwab schwab@suse.de
Tue Mar 18 08:51:56 GMT 2025


On Mär 18 2025, Samuel Zeter wrote:

> diff --git a/libio/fileops.c b/libio/fileops.c
> index a59e248142..7921fa0fb2 100644
> --- a/libio/fileops.c
> +++ b/libio/fileops.c
> @@ -1328,6 +1328,10 @@ _IO_file_xsgetn (FILE *fp, void *data, size_t n)
>  
>    want = n;
>  
> +  /* Set the stream to byte oriented */
> +  if (fp->_mode == 0)
> +    _IO_fwide (fp, -1);
> +
>    if (fp->_IO_buf_base == NULL)
>      {
>        /* Maybe we already have a push back pointer.  */
> diff --git a/libio/genops.c b/libio/genops.c
> index c3178d9a97..8537a20a92 100644
> --- a/libio/genops.c
> +++ b/libio/genops.c
> @@ -296,8 +296,6 @@ __underflow (FILE *fp)
>    if (_IO_vtable_offset (fp) == 0 && _IO_fwide (fp, -1) != -1)
>      return EOF;
>  
> -  if (fp->_mode == 0)
> -    _IO_fwide (fp, -1);
>    if (_IO_in_put_mode (fp))
>      if (_IO_switch_to_get_mode (fp) == EOF)
>        return EOF;

__underflow is also called in other places.  Do they need to be updated?

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


More information about the Libc-alpha mailing list