blob: 83b7605b9511af6300e7c825cc8a3e0596f31a44 [file] [log] [blame]
Ted Kremenekcdc3a892012-08-24 20:39:55 +00001// RUN: %clang_cc1 -verify -analyze -analyzer-checker=core,alpha.security.ArrayBound -analyzer-store=region %s
Ted Kremenek14553ab2009-01-30 00:08:43 +00002
3struct tea_cheese { unsigned magic; };
4typedef struct tea_cheese kernel_tea_cheese_t;
5extern kernel_tea_cheese_t _wonky_gesticulate_cheese;
6
7// This test case exercises the ElementRegion::getRValueType() logic.
8
Ted Kremenekab6d6222009-11-11 17:17:06 +00009void test1( void ) {
Ted Kremenek14553ab2009-01-30 00:08:43 +000010 kernel_tea_cheese_t *wonky = &_wonky_gesticulate_cheese;
11 struct load_wine *cmd = (void*) &wonky[1];
Tom Careef52bcb2010-08-24 21:09:07 +000012 cmd = cmd;
Ted Kremenek14553ab2009-01-30 00:08:43 +000013 char *p = (void*) &wonky[1];
Zhongxing Xuccb16162009-05-06 08:08:27 +000014 kernel_tea_cheese_t *q = &wonky[1];
Ted Kremenek39abcdf2009-08-01 05:59:39 +000015 // This test case tests both the RegionStore logic (doesn't crash) and
16 // the out-of-bounds checking. We don't expect the warning for now since
17 // out-of-bound checking is temporarily disabled.
Zhongxing Xu58e689f2009-11-11 12:33:27 +000018 kernel_tea_cheese_t r = *q; // expected-warning{{Access out-of-bound array element (buffer overflow)}}
Ted Kremenek14553ab2009-01-30 00:08:43 +000019}
Ted Kremenekab6d6222009-11-11 17:17:06 +000020
21void test1_b( void ) {
22 kernel_tea_cheese_t *wonky = &_wonky_gesticulate_cheese;
23 struct load_wine *cmd = (void*) &wonky[1];
Tom Careef52bcb2010-08-24 21:09:07 +000024 cmd = cmd;
Ted Kremenekab6d6222009-11-11 17:17:06 +000025 char *p = (void*) &wonky[1];
26 *p = 1; // expected-warning{{Access out-of-bound array element (buffer overflow)}}
27}