File tree Expand file tree Collapse file tree
cpp/ql/src/Likely Bugs/Memory Management Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77The expression <code >ptr + a < ptr</code > is equivalent to <code >a <
880</code >, and an optimizing compiler is likely to make that replacement,
99thereby removing a range check that might have been necessary for security.
10- If `a` is known to be non-negative, the compiler can even replace <code >ptr +
10+ If < code >a</ code > is known to be non-negative, the compiler can even replace <code >ptr +
1111a < ptr</code > with <code >false</code >.
1212</p >
1313
1414<p >
1515The reason is that pointer arithmetic overflow in C/C++ is undefined
1616behavior. The optimizing compiler can assume that the program has no
17- undefined behavior, which means that adding a positive number to ` ptr` cannot
18- produce a pointer less than ` ptr` .
17+ undefined behavior, which means that adding a positive number to < code > ptr</ code > cannot
18+ produce a pointer less than < code > ptr</ code > .
1919</p >
2020</overview >
2121<recommendation >
@@ -63,7 +63,7 @@ range of an allocation between <code>ptr</code> and <code>ptr_end</code>.
6363<sample src =" PointerOverflow-good.cpp" />
6464</example >
6565<references >
66- <li ><a href =" https://blog.regehr.org/archives/1395" >Pointer Overflow Checking [Embedded in Academia] </a ></li >
67- <li ><a href =" https://lwn.net/Articles/278137/" >GCC and pointer overflows [LWN] </a ></li >
66+ <li >Embedded in Academia: <a href =" https://blog.regehr.org/archives/1395" >Pointer Overflow Checking</a >. </li >
67+ <li >LWN: <a href =" https://lwn.net/Articles/278137/" >GCC and pointer overflows</a >. </li >
6868</references >
6969</qhelp >
You can’t perform that action at this time.
0 commit comments