Debian Codegraph @

gcc/testsuite/c-c++-common/analyzer/raw-data-cst-pr117262-2.c

raw
1 #include "analyzer-decls.h"
2
3 extern void use (unsigned char);
4
5 void
6 test ()
7 {
8 const unsigned char meow_bytes[] = {
9 0x69, 0x6e, 0x74, 0x0a, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a,
10 0x7b, 0x0a, 0x20, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x20, 0x75, 0x6e,
11 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x20, 0x63, 0x68, 0x61, 0x72, 0x20,
12 0x6d, 0x65, 0x6f, 0x77, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, 0x5b, 0x5d,
13 0x20, 0x3d, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x0a, 0x20, 0x20,
14 0x7d, 0x3b, 0x0a, 0x20, 0x20, 0x73, 0x68, 0x6f, 0x72, 0x74, 0x20, 0x6d,
15 };
16
17 /* Verify that analyzer "knows" the values of individual bytes in
18 the array. */
19
20 /* First row. */
21 __analyzer_eval (meow_bytes[0] == 0x69); /* { dg-warning "TRUE" } */
22 __analyzer_eval (meow_bytes[1] == 0x6e); /* { dg-warning "TRUE" } */
23 __analyzer_eval (meow_bytes[11] == 0x0a); /* { dg-warning "TRUE" } */
24
25 /* Second row. */
26 __analyzer_eval (meow_bytes[12] == 0x7b); /* { dg-warning "TRUE" } */
27 __analyzer_eval (meow_bytes[23] == 0x6e); /* { dg-warning "TRUE" } */
28
29 /* Final row. */
30 __analyzer_eval (meow_bytes[60] == 0x7d); /* { dg-warning "TRUE" } */
31 __analyzer_eval (meow_bytes[70] == 0x20); /* { dg-warning "TRUE" } */
32 __analyzer_eval (meow_bytes[71] == 0x6d); /* { dg-warning "TRUE" } */
33
34 use (meow_bytes[-1]); /* { dg-warning "stack-based buffer under-read" } */
35 use (meow_bytes[72]); /* { dg-warning "stack-based buffer over-read" } */
36 }