[Bug gcov-profile/101773] errors when writing to .gcda file are not checked

marxin at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Aug 4 15:12:00 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101773

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |NEW

--- Comment #7 from Martin Liška <marxin at gcc dot gnu.org> ---
(In reply to Vincent Lefèvre from comment #6)
> Created attachment 51259 [details]
> added missing error check on fclose in gcc/gcov-io.c
> 
> Well, not all errors are detected. There is a missing test in gcc/gcov-io.c
> for fclose (which does a write system call to flush the buffers):
> 
> --- a/gcc/gcov-io.c
> +++ b/gcc/gcov-io.c
> @@ -199,7 +199,8 @@ gcov_close (void)
>  {
>    if (gcov_var.file)
>      {
> -      fclose (gcov_var.file);
> +      if (fclose (gcov_var.file))
> +       gcov_var.error = 1;
>        gcov_var.file = 0;
>      }
>    gcov_var.mode = 0;
> 
> (also in attachment). I've tested this patch, and it solves my problem:

Great job! I was aware of the fclose, but didn't realize it fails during
flushing.
May I please install the patch on your behalf?


More information about the Gcc-bugs mailing list