aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorImmad Mir <mirimmad@outlook.com>2022-07-06 21:38:27 +0530
committerImmad Mir <mirimmad@outlook.com>2022-07-06 21:38:41 +0530
commitacb696b792eeab92167f516b5236ed9242e62deb (patch)
treeb2effa75b87708b06eb557dbc339ed73f4396a4b
parent3a6de2b2db500d76ac141a6ef85d336bd0f8430b (diff)
downloadgcc-acb696b792eeab92167f516b5236ed9242e62deb.zip
gcc-acb696b792eeab92167f516b5236ed9242e62deb.tar.gz
gcc-acb696b792eeab92167f516b5236ed9242e62deb.tar.bz2
analyzer: add testcase of using closed fd without warning.
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>
-rw-r--r--gcc/testsuite/gcc.dg/analyzer/fd-4.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-4.c b/gcc/testsuite/gcc.dg/analyzer/fd-4.c
index c992db6..fcfa616 100644
--- a/gcc/testsuite/gcc.dg/analyzer/fd-4.c
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-4.c
@@ -1,3 +1,5 @@
+#include <stdio.h>
+
int open(const char *, int mode);
void close(int fd);
int write (int fd, void *buf, int nbytes);
@@ -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 } */
}
}
+
+void
+test_5 (const char *path)
+{
+ int fd = open (path, O_RDWR);
+ close(fd);
+ printf("%d", fd); /* { dg-bogus "'printf' on a closed file descriptor 'fd'" } */
+} \ No newline at end of file