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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I think the difference is
https://sourceware.org/git/?p=glibc.git;a=commit;h=c1760eaf3b575ad174fd88b252fd16bd525fa818
which added __attribute__((malloc)) to fdopen among other things.
It is strange that it is reported just for fwrite and not for fgetc in the
other function though, both access potentially NULL stream.
Probably because {fwrite,putc,fputc,fputs}{,_unlocked} and printf family are
builtins and have nonnull attribute for the FILE * argument, but fgetc or fread
is not and glibc
doesn't use nonnull for those.

Shall we than use
2023-03-29  Jakub Jelinek  <ja...@redhat.com>

        PR analyzer/107396
        * gcc.dg/analyzer/pipe-glibc.c (read_from_pie, write_to_pipe): Exit
        if fdopen returns NULL.

--- gcc/testsuite/gcc.dg/analyzer/pipe-glibc.c.jj       2022-10-25
10:37:28.106531709 +0200
+++ gcc/testsuite/gcc.dg/analyzer/pipe-glibc.c  2023-03-29 19:14:48.789766475
+0200
@@ -13,6 +13,8 @@ read_from_pipe (int file)
   FILE *stream;
   int c;
   stream = fdopen (file, "r");
+  if (stream == NULL)
+    exit (EXIT_FAILURE);
   while ((c = fgetc (stream)) != EOF)
     putchar (c);
   fclose (stream);
@@ -25,6 +27,8 @@ write_to_pipe (int file)
 {
   FILE *stream;
   stream = fdopen (file, "w");
+  if (stream == NULL)
+    exit (EXIT_FAILURE);
   fprintf (stream, "hello, world!\n");
   fprintf (stream, "goodbye, world!\n");
   fclose (stream);
because this warning is not what the test wants to verify?

Reply via email to