]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
analyzer: add testcase of using closed fd without warning.
authorImmad Mir <mirimmad@outlook.com>
Wed, 6 Jul 2022 16:08:27 +0000 (21:38 +0530)
committerImmad Mir <mirimmad@outlook.com>
Wed, 6 Jul 2022 16:08:41 +0000 (21:38 +0530)
This patch adds a testcase for passing a closed fd to a function
that does not emit any warning.

gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/fd-4.c: Add a new testcase to demonstrate
passsing of a closed file descriptor to a function that does
not emit any warning.

Signed-off-by: Immad Mir <mirimmad@outlook.com>
gcc/testsuite/gcc.dg/analyzer/fd-4.c

index c992db619e754a01298e6807a21ecb17a0246b51..fcfa6168efae9f286ac2afe91e7e5e7071ef1630 100644 (file)
@@ -1,3 +1,5 @@
+#include <stdio.h>\r
+\r
 int open(const char *, int mode);\r
 void close(int fd);\r
 int write (int fd, void *buf, int nbytes);\r
@@ -60,3 +62,11 @@ test_4 (const char *path, void *buf)
         /* {dg-message "\\(3\\) 'write' on closed file descriptor 'fd'; 'close' was at \\(2\\)" "" {target *-*-*} .-1 } */\r
     }\r
 }\r
+\r
+void\r
+test_5 (const char *path)\r
+{\r
+    int fd = open (path, O_RDWR);\r
+    close(fd);\r
+    printf("%d", fd); /* { dg-bogus "'printf' on a closed file descriptor 'fd'" } */\r
+}
\ No newline at end of file