Skip to content

Commit 53a106f

Browse files
committed
Suggest an alternative way to write the check
1 parent 6940157 commit 53a106f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ code bases.
7171

7272
To avoid pointer addition overflow, it is necessary to perform the addition
7373
on integers, for example using
74-
``(uintptr_t)ptr + unsigned_offset < (uintptr_t)ptr``.
74+
``(uintptr_t)ptr + unsigned_offset < (uintptr_t)ptr``. Sometimes, it is also
75+
possible to rewrite checks by only comparing the offset. For example,
76+
``ptr + offset < end_ptr && ptr + offset >= ptr`` can be written as
77+
``offset < (uintptr_t)(end_ptr - ptr)``.
7578

7679
Undefined behavior due to pointer addition overflow can be reliably detected
7780
using ``-fsanitize=pointer-overflow``. It is also possible to use

0 commit comments

Comments
 (0)