public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-6639] analyzer, testsuite: add test coverage for various builtins
@ 2023-03-13 18:54 David Malcolm
0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2023-03-13 18:54 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:fa9d3aa67894c8cadf9840be424b566a8c53c8e4
commit r13-6639-gfa9d3aa67894c8cadf9840be424b566a8c53c8e4
Author: David Malcolm <dmalcolm@redhat.com>
Date: Mon Mar 13 14:53:04 2023 -0400
analyzer, testsuite: add test coverage for various builtins
gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/exec-1.c: New test.
* gcc.dg/analyzer/snprintf-concat.c: New test.
* gcc.dg/analyzer/vsnprintf-1.c: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diff:
---
gcc/testsuite/gcc.dg/analyzer/exec-1.c | 43 +++++++++++++++++++++++++
gcc/testsuite/gcc.dg/analyzer/snprintf-concat.c | 35 ++++++++++++++++++++
gcc/testsuite/gcc.dg/analyzer/vsnprintf-1.c | 11 +++++++
3 files changed, 89 insertions(+)
diff --git a/gcc/testsuite/gcc.dg/analyzer/exec-1.c b/gcc/testsuite/gcc.dg/analyzer/exec-1.c
new file mode 100644
index 00000000000..6b71118bd54
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/exec-1.c
@@ -0,0 +1,43 @@
+#define NULL ((void *)0)
+
+extern int execl(const char *pathname, const char *arg, ...);
+extern int execlp(const char *file, const char *arg, ...);
+extern int execle(const char *pathname, const char *arg, ...);
+extern int execv(const char *pathname, char *const argv[]);
+extern int execvp(const char *file, char *const argv[]);
+extern int execvpe(const char *file, char *const argv[], char *const envp[]);
+
+int test_execl_ls_al ()
+{
+ return execl ("/usr/bin/ls", "ls", "-al", NULL);
+}
+
+int test_execlpl_ls_al ()
+{
+ return execlp ("ls", "ls", "-al", NULL);
+}
+
+int test_execle_ls_al ()
+{
+ const char *env[3] = {"FOO=BAR", "BAZ", NULL};
+ return execl ("/usr/bin/ls", "ls", "-al", NULL, env);
+}
+
+int test_execv_ls_al ()
+{
+ char *argv[3] = {"ls", "-al", NULL};
+ return execv ("/usr/bin/ls", argv);
+}
+
+int test_execvp_ls_al ()
+{
+ char *argv[3] = {"ls", "-al", NULL};
+ return execvp ("ls", argv);
+}
+
+int test_execvpe_ls_al ()
+{
+ char *env[3] = {"FOO=BAR", "BAZ", NULL};
+ char *argv[3] = {"ls", "-al", NULL};
+ return execvpe ("ls", argv, env);
+}
diff --git a/gcc/testsuite/gcc.dg/analyzer/snprintf-concat.c b/gcc/testsuite/gcc.dg/analyzer/snprintf-concat.c
new file mode 100644
index 00000000000..a557dee6e44
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/snprintf-concat.c
@@ -0,0 +1,35 @@
+typedef __SIZE_TYPE__ size_t;
+#define NULL ((void *)0)
+
+extern size_t
+strlen(const char* __s) __attribute__((__nothrow__, __leaf__))
+__attribute__((__pure__)) __attribute__((__nonnull__(1)));
+
+extern void*
+malloc(size_t __size) __attribute__((__nothrow__, __leaf__))
+__attribute__((__malloc__)) __attribute__((__alloc_size__(1)));
+
+extern int
+snprintf(char* __restrict __s, size_t size, const char* __restrict, ...)
+ __attribute__((__nothrow__));
+
+char *
+test_1 (const char *a, const char *b)
+{
+ size_t sz = strlen (a) + strlen (b) + 2;
+ char *p = malloc (sz);
+ if (!p)
+ return NULL;
+ snprintf (p, sz, "%s/%s", a, b);
+ return p;
+}
+
+void
+test_2 (const char *a, const char *b)
+{
+ size_t sz = strlen (a) + strlen (b) + 2;
+ char *p = malloc (sz); /* { dg-message "allocated here" "PR 107017" { xfail *-*-* } } */
+ if (!p)
+ return;
+ snprintf (p, sz, "%s/%s", a, b); /* { dg-warning "leak of 'p'" "PR 107017" { xfail *-*-* } } */
+}
diff --git a/gcc/testsuite/gcc.dg/analyzer/vsnprintf-1.c b/gcc/testsuite/gcc.dg/analyzer/vsnprintf-1.c
new file mode 100644
index 00000000000..209c4b6cbb6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/vsnprintf-1.c
@@ -0,0 +1,11 @@
+typedef __SIZE_TYPE__ size_t;
+
+int
+my_snprintf(char *pos, size_t left, const char *fmt, ...)
+{
+ __builtin_va_list ap;
+ __builtin_va_start(ap, fmt);
+ const int len = __builtin_vsnprintf(pos, left, fmt, ap);
+ __builtin_va_end(ap);
+ return len;
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-03-13 18:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-13 18:54 [gcc r13-6639] analyzer, testsuite: add test coverage for various builtins David Malcolm
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).