diff mbox series

[3/3] analyzer: add a new testcase to demonstrate passsing of a file descriptor to a function that does not emit any warning

Message ID CY4PR1801MB1910CCF78855681CBB47335AC6809@CY4PR1801MB1910.namprd18.prod.outlook.com
State New
Headers show
Series [1/3] analyzer: show close event for use_after_close diagnostic | expand

Commit Message

Immad Mir July 6, 2022, 2:25 p.m. UTC
gcc/testsuite/ChangeLog:
	* gcc.dg/analyzer/fd-4.c: Add a new testcase to demonstrate passsing
	of a 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 | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

David Malcolm July 6, 2022, 3:37 p.m. UTC | #1
On Wed, 2022-07-06 at 19:55 +0530, Immad Mir wrote:
> gcc/testsuite/ChangeLog:
>         * gcc.dg/analyzer/fd-4.c: Add a new testcase to demonstrate
> passsing
>         of a file descriptor to a function that does not emit any
> warning.

The patch itself is OK for trunk, but the initial line of the commit
message is probably too long - this gets used as the title of the
commit in various git UIs.  I can't remember the recommended limit, it
might be 80 chars (which can be hard when the leading "analyzer: "
takes up 10 chars).

Please reduce the length before pushing, maybe to:
  analyzer: add testcase of using closed fd without warning
or somesuch

Thanks
Dave


> 
> Signed-off-by: Immad Mir <mirimmad@outlook.com>
> ---
>  gcc/testsuite/gcc.dg/analyzer/fd-4.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-4.c
> b/gcc/testsuite/gcc.dg/analyzer/fd-4.c
> index c992db619e7..fcfa6168efa 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
diff mbox series

Patch

diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-4.c b/gcc/testsuite/gcc.dg/analyzer/fd-4.c
index c992db619e7..fcfa6168efa 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