[clang] [clang][analyzer] Add checker 'core.NullPointerArithm' (PR #157129)

Donát Nagy via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 8 05:44:24 PDT 2025


================
@@ -205,6 +205,47 @@ pointers with a specified address space. If the option is set to false, then
 reports from the specific x86 address spaces 256, 257 and 258 are still
 suppressed, but null dereferences from other address spaces are reported.
 
+.. _core-NullPointerArithm:
+
+core.NullPointerArithm (C, C++)
+"""""""""""""""""""""""""""""""
+Check for undefined arithmetic operations with null pointers.
+
+The checker can detect the following cases:
+
+  - `p + x` and `x + p` where `p` is a null pointer and `x` is a nonzero integer
+    value.
+  - `p - x` where `p` is a null pointer and `x` is a nonzero integer
+    value.
+  - `p1` - `p2` where one of `p1` and `p2` is null and the other a non-null
+    pointer.
----------------
NagyDonat wrote:

```suggestion
  - ``p + x`` and ``x + p`` where ``p`` is a null pointer and ``x`` is a nonzero
    integer value.
  - ``p - x`` where ``p`` is a null pointer and ``x`` is a nonzero integer
    value.
  - ``p1 - p2`` where one of ``p1`` and ``p2`` is null and the other a non-null
    pointer.
```
In this RST format you need to use double backticks for code fragments. (Single backticks – which would mean code fragments in Markdown, e.g. in github comments – introduce links in RST. I also frequently confuse these when I need to write RST.)

https://github.com/llvm/llvm-project/pull/157129


More information about the cfe-commits mailing list