public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5654] analyzer: add deref-before-check-qemu-qtest_rsp_args.c test case Date: Thu, 2 Feb 2023 14:13:18 +0000 (GMT) [thread overview] Message-ID: <20230202141318.1B3763858C60@sourceware.org> (raw) 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; +}
reply other threads:[~2023-02-02 14:13 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=20230202141318.1B3763858C60@sourceware.org \ --to=dmalcolm@gcc.gnu.org \ --cc=gcc-cvs@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: linkBe 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).