1 #include <stdlib.h> 2 #include "check_debug.h" 3 4 struct foo { 5 int x, y, z; 6 int count; 7 char msg[0]; 8 }; 9 10 struct bar { 11 int x, y, z; 12 int count; 13 char msg[1]; 14 }; 15 16 struct outer1 { 17 int x, y, z; 18 struct foo foo; 19 }; 20 21 struct outer2 { 22 int x, y, z; 23 struct bar bar; 24 }; 25 26 int test(void) 27 { 28 struct foo *p; 29 struct bar *q; 30 struct outer1 *a; 31 struct outer2 *b; 32 33 p = malloc(sizeof(*p) + 100); 34 __smatch_buf_size(p->msg); 35 36 q = malloc(sizeof(*q) + 100); 37 __smatch_buf_size(q->msg); 38 39 a = malloc(sizeof(*a) + 100); 40 __smatch_buf_size(a->foo); 41 42 b = malloc(sizeof(*b) + 100); 43 __smatch_buf_size(b->bar); 44 } 45 46 /* 47 * check-name: smatch buf size #8 48 * check-command: smatch -I.. sm_buf_size8.c 49 * 50 * check-output-start 51 sm_buf_size8.c:34 test() buf size: 'p->msg' 100 elements, 100 bytes 52 sm_buf_size8.c:37 test() buf size: 'q->msg' 101 elements, 101 bytes 53 sm_buf_size8.c:40 test() buf size: 'a->foo' 0 elements, 116 bytes 54 sm_buf_size8.c:43 test() buf size: 'b->bar' 0 elements, 120 bytes 55 * check-output-end 56 */ 57