public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/99716] New: -Wanalyzer-double-fclose when fclose is called inside a loop
@ 2021-03-22 15:49 rjones at redhat dot com
  2021-03-22 16:25 ` [Bug analyzer/99716] " dmalcolm at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: rjones at redhat dot com @ 2021-03-22 15:49 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99716
           Summary: -Wanalyzer-double-fclose when fclose is called inside
                    a loop
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: rjones at redhat dot com
  Target Milestone: ---

This seems pretty bogus to me:

#include <stdio.h>
#include <stdlib.h>

int
main ()
{
  int i;

  for (i = 0; i < 2; ++i) {
    FILE *fp = fopen ("/tmp/test", "w");
    fprintf (fp, "hello");
    fclose (fp);
  }
  exit (EXIT_SUCCESS);
}

$ gcc -O2 -fanalyzer /tmp/fclose-loop.c -o /tmp/fclose-loop
/tmp/fclose-loop.c: In function ‘main’:
/tmp/fclose-loop.c:12:5: warning: double ‘fclose’ of FILE ‘fp’
[-Wanalyzer-double-fclose]
   12 |     fclose (fp);
      |     ^~~~~~~~~~~
  ‘main’: events 1-7
    |
    |    9 |   for (i = 0; i < 2; ++i) {
    |      |               ~~^~~
    |      |                 |
    |      |                 (1) following ‘true’ branch (when ‘i != 2’)...
    |      |                 (5) following ‘true’ branch (when ‘i != 2’)...
    |   10 |     FILE *fp = fopen ("/tmp/test", "w");
    |      |                ~~~~~~~~~~~~~~~~~~~~~~~~
    |      |                |
    |      |                (2) ...to here
    |      |                (3) opened here
    |      |                (6) ...to here
    |   11 |     fprintf (fp, "hello");
    |   12 |     fclose (fp);
    |      |     ~~~~~~~~~~~  
    |      |     |
    |      |     (4) first ‘fclose’ here
    |      |     (7) second ‘fclose’ here; first ‘fclose’ was at (4)

This is with:
gcc-11.0.0-0.19.fc35.x86_64

I do not have any later version of GCC to test, but also I don't see any
other bug about this.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-03-25  0:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-22 15:49 [Bug analyzer/99716] New: -Wanalyzer-double-fclose when fclose is called inside a loop rjones at redhat dot com
2021-03-22 16:25 ` [Bug analyzer/99716] " dmalcolm at gcc dot gnu.org
2021-03-23 16:12 ` dmalcolm at gcc dot gnu.org
2021-03-23 17:09 ` rjones at redhat dot com
2021-03-23 20:38 ` dmalcolm at gcc dot gnu.org
2021-03-25  0:48 ` cvs-commit at gcc dot gnu.org
2021-03-25  0:53 ` dmalcolm at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).