1 // RUN: %clang_analyze_cc1 -analyzer-checker=security.PointerSub -analyzer-output=text -verify %s
4 int a
[3]; // expected-note{{Array at the left-hand side of subtraction}}
5 int b
[3]; // expected-note{{Array at the right-hand side of subtraction}}
6 int d
= &a
[2] - &b
[0]; // expected-warning{{Subtraction of two pointers that do not point into the same array is undefined behavior}} \
7 // expected-note{{Subtraction of two pointers that do not point into the same array is undefined behavior}}
11 int a
[3]; // expected-note{{Array at the right-hand side of subtraction}}
12 int b
[3]; // expected-note{{Array at the left-hand side of subtraction}}
15 int d
= p2
- p1
; // expected-warning{{Subtraction of two pointers that do not point into the same array is undefined behavior}} \
16 // expected-note{{Subtraction of two pointers that do not point into the same array is undefined behavior}}
23 return &a
.array
[3] - &b
.array
[2]; // expected-warning{{Subtraction of two pointers that do not point into the same array is undefined behavior}} \
24 // expected-note{{Subtraction of two pointers that do not point into the same array is undefined behavior}}
29 int array1
[5]; // expected-note{{Array at the left-hand side of subtraction}}
30 int array2
[5]; // expected-note{{Array at the right-hand side of subtraction}}
32 return &a
.array1
[3] - &a
.array2
[4]; // expected-warning{{Subtraction of two pointers that do not point into the same array is undefined behavior}} \
33 // expected-note{{Subtraction of two pointers that do not point into the same array is undefined behavior}}
38 static int x
[10][10]; // expected-note2{{Array at the left-hand side of subtraction}}
40 char *z
= ((char *) y1
) + 2;
41 int *y2
= (int *)(z
- 2);
42 int *y3
= ((int *)x
) + 35; // This is offset for [3][5].
44 d
= y2
- y1
; // expected-warning{{Subtraction of two pointers that do not point into the same array is undefined behavior}} \
45 // expected-note{{Subtraction of two pointers that do not point into the same array is undefined behavior}}
46 d
= y3
- y1
; // expected-warning{{Subtraction of two pointers that do not point into the same array is undefined behavior}} \
47 // expected-note{{Subtraction of two pointers that do not point into the same array is undefined behavior}}