@@ -1544,6 +1544,49 @@ Warn on ``mmap()`` calls with both writable and executable access.
1544
1544
// code
1545
1545
}
1546
1546
1547
+ .. _security-PointerSub :
1548
+
1549
+ security.PointerSub (C)
1550
+ """""""""""""""""""""""
1551
+ Check for pointer subtractions on two pointers pointing to different memory
1552
+ chunks. According to the C standard §6.5.6 only subtraction of pointers that
1553
+ point into (or one past the end) the same array object is valid (for this
1554
+ purpose non-array variables are like arrays of size 1). This checker only
1555
+ searches for different memory objects at subtraction, but does not check if the
1556
+ array index is correct. Furthermore, only cases are reported where
1557
+ stack-allocated objects are involved (no warnings on pointers to memory
1558
+ allocated by `malloc `).
1559
+
1560
+ .. code-block :: c
1561
+
1562
+ void test() {
1563
+ int a, b, c[10], d[10];
1564
+ int x = &c[3] - &c[1];
1565
+ x = &d[4] - &c[1]; // warn: 'c' and 'd' are different arrays
1566
+ x = (&a + 1) - &a;
1567
+ x = &b - &a; // warn: 'a' and 'b' are different variables
1568
+ }
1569
+
1570
+ struct S {
1571
+ int x[10];
1572
+ int y[10];
1573
+ };
1574
+
1575
+ void test1() {
1576
+ struct S a[10];
1577
+ struct S b;
1578
+ int d = &a[4] - &a[6];
1579
+ d = &a[0].x[3] - &a[0].x[1];
1580
+ d = a[0].y - a[0].x; // warn: 'S.b' and 'S.a' are different objects
1581
+ d = (char *)&b.y - (char *)&b.x; // warn: different members of the same object
1582
+ d = (char *)&b.y - (char *)&b; // warn: object of type S is not the same array as a member of it
1583
+ }
1584
+
1585
+ There may be existing applications that use code like above for calculating
1586
+ offsets of members in a structure, using pointer subtractions. This is still
1587
+ undefined behavior according to the standard and code like this can be replaced
1588
+ with the `offsetof ` macro.
1589
+
1547
1590
.. _security-putenv-stack-array :
1548
1591
1549
1592
security.PutenvStackArray (C)
@@ -2761,49 +2804,6 @@ Check for pointer arithmetic on locations other than array elements.
2761
2804
p = &x + 1; // warn
2762
2805
}
2763
2806
2764
- .. _alpha-core-PointerSub :
2765
-
2766
- alpha.core .PointerSub (C)
2767
- """""""""""""""""""""""""
2768
- Check for pointer subtractions on two pointers pointing to different memory
2769
- chunks. According to the C standard §6.5.6 only subtraction of pointers that
2770
- point into (or one past the end) the same array object is valid (for this
2771
- purpose non-array variables are like arrays of size 1). This checker only
2772
- searches for different memory objects at subtraction, but does not check if the
2773
- array index is correct. Furthermore, only cases are reported where
2774
- stack-allocated objects are involved (no warnings on pointers to memory
2775
- allocated by `malloc `).
2776
-
2777
- .. code-block :: c
2778
-
2779
- void test() {
2780
- int a, b, c[10], d[10];
2781
- int x = &c[3] - &c[1];
2782
- x = &d[4] - &c[1]; // warn: 'c' and 'd' are different arrays
2783
- x = (&a + 1) - &a;
2784
- x = &b - &a; // warn: 'a' and 'b' are different variables
2785
- }
2786
-
2787
- struct S {
2788
- int x[10];
2789
- int y[10];
2790
- };
2791
-
2792
- void test1() {
2793
- struct S a[10];
2794
- struct S b;
2795
- int d = &a[4] - &a[6];
2796
- d = &a[0].x[3] - &a[0].x[1];
2797
- d = a[0].y - a[0].x; // warn: 'S.b' and 'S.a' are different objects
2798
- d = (char *)&b.y - (char *)&b.x; // warn: different members of the same object
2799
- d = (char *)&b.y - (char *)&b; // warn: object of type S is not the same array as a member of it
2800
- }
2801
-
2802
- There may be existing applications that use code like above for calculating
2803
- offsets of members in a structure, using pointer subtractions. This is still
2804
- undefined behavior according to the standard and code like this can be replaced
2805
- with the `offsetof ` macro.
2806
-
2807
2807
.. _alpha-core-StackAddressAsyncEscape :
2808
2808
2809
2809
alpha.core .StackAddressAsyncEscape (ObjC)
0 commit comments