1 #include <string.h>
2 #include "analyzer-decls.h"
3
4 const char* test_literal (int x)
5 {
6 char *p = __builtin_strchr ("123", x); /* { dg-message "when '__builtin_strchr' returns non-NULL" } */
7 if (p)
8 {
9 __analyzer_eval (*p == x); /* { dg-message "UNKNOWN" } */
10 /* TODO: this ought to be TRUE, but it's unclear that it's
11 worth stashing this constraint. */
12 *p = 'A'; /* { dg-warning "write to string literal" } */
13 }
14 return p;
15 }
16
17 void test_2 (const char *s, int c)
18 {
19 char *p = __builtin_strchr (s, c); /* { dg-message "when '__builtin_strchr' returns NULL"} */
20 *p = 'A'; /* { dg-warning "dereference of NULL 'p'" "null deref" } */
21 }
22
23 void test_3 (const char *s, int c)
24 {
25 char *p = strchr (s, c); /* { dg-message "when 'strchr' returns NULL"} */
26 *p = 'A'; /* { dg-warning "dereference of NULL 'p'" "null deref" } */
27 }