From: David Malcolm <dmalcolm@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: David Malcolm <dmalcolm@redhat.com>
Subject: [pushed] analyzer: add deref-before-check-qemu-qtest_rsp_args.c test case
Date: Thu, 2 Feb 2023 09:15:03 -0500 [thread overview]
Message-ID: <20230202141503.913418-1-dmalcolm@redhat.com> (raw)
Successfully regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r13-5654-g598e10cf415f0a.
gcc/testsuite/ChangeLog:
* gcc.dg/analyzer/deref-before-check-qemu-qtest_rsp_args.c: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
---
.../deref-before-check-qemu-qtest_rsp_args.c | 73 +++++++++++++++++++
1 file changed, 73 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/analyzer/deref-before-check-qemu-qtest_rsp_args.c
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;
+}
--
2.26.3
reply other threads:[~2023-02-02 14:15 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230202141503.913418-1-dmalcolm@redhat.com \
--to=dmalcolm@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).