public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-5654] analyzer: add deref-before-check-qemu-qtest_rsp_args.c test case
@ 2023-02-02 14:13 David Malcolm
  0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2023-02-02 14:13 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:598e10cf415f0a53eab2b1e63980531c60d673b7

commit r13-5654-g598e10cf415f0a53eab2b1e63980531c60d673b7
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Thu Feb 2 09:11:31 2023 -0500

    analyzer: add deref-before-check-qemu-qtest_rsp_args.c test case
    
    gcc/testsuite/ChangeLog:
            * gcc.dg/analyzer/deref-before-check-qemu-qtest_rsp_args.c: New test.
    
    Signed-off-by: David Malcolm <dmalcolm@redhat.com>

Diff:
---
 .../deref-before-check-qemu-qtest_rsp_args.c       | 73 ++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/analyzer/deref-before-check-qemu-qtest_rsp_args.c b/gcc/testsuite/gcc.dg/analyzer/deref-before-check-qemu-qtest_rsp_args.c
new file mode 100644
index 00000000000..2b3ad8c5fb3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/deref-before-check-qemu-qtest_rsp_args.c
@@ -0,0 +1,73 @@
+/* Reduced from qemu-7.2.0's tests/qtest/libqtest.c.  */
+
+#define TRUE 1
+#define NULL ((void *)0)
+
+#define g_assert(expr) \
+  do {									\
+    if (expr) ; else /* { dg-warning "check of '\\*words' for NULL after already dereferencing it" } */ \
+      g_assertion_message_expr (#expr);			\
+} while (0)
+
+void    g_assertion_message_expr        (const char     *expr) __attribute__((noreturn));
+
+extern int strcmp (const char *__s1, const char *__s2)
+  __attribute__ ((__nothrow__ , __leaf__, __pure__, __nonnull__ (1, 2)));
+typedef char gchar;
+typedef int gint;
+typedef gint gboolean;
+typedef struct _GString GString;
+
+struct _GString
+{
+  gchar *str;
+  /* [...snip...] */
+};
+
+extern
+gchar* g_string_free (GString *string,
+		      gboolean free_segment);
+extern
+gchar** g_strsplit (const gchar *string,
+		    const gchar *delimiter,
+		    gint max_tokens);
+extern
+void g_strfreev (gchar **str_array);
+
+typedef struct QTestState QTestState;
+typedef GString* (*QTestRecvFn)(QTestState *);
+
+typedef struct QTestClientTransportOps {
+    /* [...snip...] */
+    QTestRecvFn recv_line;
+} QTestTransportOps;
+
+struct QTestState
+{
+    /* [...snip...] */
+    QTestTransportOps ops;
+    /* [...snip...] */
+};
+
+gchar **qtest_rsp_args(QTestState *s, int expected_args)
+{
+    GString *line;
+    gchar **words;
+    /* [...snip...] */
+
+redo:
+    line = s->ops.recv_line(s);
+    words = g_strsplit(line->str, " ", 0);
+    g_string_free(line, TRUE);
+
+    if (strcmp(words[0], "IRQ") == 0) { /* { dg-message "pointer '\\*words' is dereferenced here" } */
+        /* [...snip...] */
+        g_strfreev(words);
+        goto redo;
+    }
+
+    g_assert(words[0] != NULL); /* { dg-message "in expansion of macro 'g_assert'" } */
+    /* [...snip...] */
+
+    return words;
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-02 14:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-02 14:13 [gcc r13-5654] analyzer: add deref-before-check-qemu-qtest_rsp_args.c test case 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).