libio: Initialize _total_written for all kinds of streams

Message ID 20250131150710.2272730-1-tuliom@ascii.art.br (mailing list archive)
State Accepted
Delegated to: Arjun Shankar
Headers
Series libio: Initialize _total_written for all kinds of streams |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Build passed
redhat-pt-bot/TryBot-32bit success Build for i686
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Test passed

Commit Message

Tulio Magno Quites Machado Filho Jan. 31, 2025, 3:07 p.m. UTC
  From: Tulio Magno Quites Machado Filho <tuliom@redhat.com>

Move the initialization code to a general place instead of keeping it
specific to file-backed streams.

Fixes: 596a61cf6b (libio: Start to return errors when flushing fwrite's buffer [BZ #29459], 2025-01-28)
Reported-by: Florian Weimer <fweimer@redhat.com>
---
 libio/fileops.c | 1 -
 libio/genops.c  | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)
  

Comments

Arjun Shankar Feb. 10, 2025, 1:49 p.m. UTC | #1
Hi Tulio,

> Move the initialization code to a general place instead of keeping it
> specific to file-backed streams.
>
> Fixes: 596a61cf6b (libio: Start to return errors when flushing fwrite's buffer [BZ #29459], 2025-01-28)
> Reported-by: Florian Weimer <fweimer@redhat.com>

This looks good to me.

Reviewed-by: Arjun Shankar <arjun@redhat.com>

> ---
>  libio/fileops.c | 1 -
>  libio/genops.c  | 1 +
>  2 files changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libio/fileops.c b/libio/fileops.c
> index 1a192b7512..a59e248142 100644
> --- a/libio/fileops.c
> +++ b/libio/fileops.c
> @@ -113,7 +113,6 @@ _IO_new_file_init_internal (struct _IO_FILE_plus *fp)
>
>    _IO_link_in (fp);
>    fp->file._fileno = -1;
> -  fp->file._total_written = 0;

OK. Stop setting it in file-backed stream specific code.

>  }
>
>  /* External version of _IO_new_file_init_internal which switches off
> diff --git a/libio/genops.c b/libio/genops.c
> index e4378ca48f..c3178d9a97 100644
> --- a/libio/genops.c
> +++ b/libio/genops.c
> @@ -611,6 +611,7 @@ _IO_no_init (FILE *fp, int flags, int orientation,
>         stream.  */
>      fp->_wide_data = (struct _IO_wide_data *) -1L;
>    fp->_freeres_list = NULL;
> +  fp->_total_written = 0;

OK. Start setting it more generally. And to double check that this is
the right place to do it:
* for file backed streams, fopen calls _IO_no_init.
* for memory backed streams, open_memstream calls _IO_init_internal,
which calls _IO_no_init.
* similarly, open_wmemstream calls _IO_no_init.

>  }
>
>  int
> --
> 2.48.1
>
  

Patch

diff --git a/libio/fileops.c b/libio/fileops.c
index 1a192b7512..a59e248142 100644
--- a/libio/fileops.c
+++ b/libio/fileops.c
@@ -113,7 +113,6 @@  _IO_new_file_init_internal (struct _IO_FILE_plus *fp)
 
   _IO_link_in (fp);
   fp->file._fileno = -1;
-  fp->file._total_written = 0;
 }
 
 /* External version of _IO_new_file_init_internal which switches off
diff --git a/libio/genops.c b/libio/genops.c
index e4378ca48f..c3178d9a97 100644
--- a/libio/genops.c
+++ b/libio/genops.c
@@ -611,6 +611,7 @@  _IO_no_init (FILE *fp, int flags, int orientation,
        stream.  */
     fp->_wide_data = (struct _IO_wide_data *) -1L;
   fp->_freeres_list = NULL;
+  fp->_total_written = 0;
 }
 
 int