Debian Codegraph @

gcc/testsuite/c-c++-common/analyzer/deref-before-check-qemu-qtest_rsp_args.c

raw
1 /* Reduced from qemu-7.2.0's tests/qtest/libqtest.c. */
2
3 #define TRUE 1
4 #define NULL ((void *)0)
5
6 #define g_assert(expr) \
7 do { \
8 if (expr) ; else /* { dg-warning "check of '\\*words' for NULL after already dereferencing it" } */ \
9 g_assertion_message_expr (#expr); \
10 } while (0)
11
12 void g_assertion_message_expr (const char *expr) __attribute__((noreturn));
13
14 extern int strcmp (const char *__s1, const char *__s2)
15 __attribute__ ((__nothrow__ , __leaf__, __pure__, __nonnull__ (1, 2)));
16 typedef char gchar;
17 typedef int gint;
18 typedef gint gboolean;
19 typedef struct _GString GString;
20
21 struct _GString
22 {
23 gchar *str;
24 /* [...snip...] */
25 };
26
27 extern
28 gchar* g_string_free (GString *string,
29 gboolean free_segment);
30 extern
31 gchar** g_strsplit (const gchar *string,
32 const gchar *delimiter,
33 gint max_tokens);
34 extern
35 void g_strfreev (gchar **str_array);
36
37 typedef struct QTestState QTestState;
38 typedef GString* (*QTestRecvFn)(QTestState *);
39
40 typedef struct QTestClientTransportOps {
41 /* [...snip...] */
42 QTestRecvFn recv_line;
43 } QTestTransportOps;
44
45 struct QTestState
46 {
47 /* [...snip...] */
48 QTestTransportOps ops;
49 /* [...snip...] */
50 };
51
52 gchar **qtest_rsp_args(QTestState *s, int expected_args)
53 {
54 GString *line;
55 gchar **words;
56 /* [...snip...] */
57
58 redo:
59 line = s->ops.recv_line(s);
60 words = g_strsplit(line->str, " ", 0);
61 g_string_free(line, TRUE);
62
63 if (strcmp(words[0], "IRQ") == 0) { /* { dg-message "pointer '\\*words' is dereferenced here" } */
64 /* [...snip...] */
65 g_strfreev(words);
66 goto redo;
67 }
68
69 g_assert(words[0] != NULL); /* { dg-message "in expansion of macro 'g_assert'" } */
70 /* [...snip...] */
71
72 return words;
73 }