[clang-tools-extra] [clang-tidy] Add new `bugprone-suspicious-pointer-arithmetics-using-sizeof` (`cert-arr39-c`) check (PR #106061)

via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 28 01:51:36 PDT 2024


whisperity wrote:

@nicovank 
> Add check and alias entries to [clang-tools-extra/docs/clang-tidy/checks/list.rst](https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/docs/clang-tidy/checks/list.rst).
> 
> Check name: this is not only sizeof. Maybe `bugprone-suspicious-pointer-scaling-arithmetic`? Others may have other ideas.

The new check will be dropped and instead the functionality is going to be integrated into **ˋbugprone-sizeof-expressionˋ**, which already checks a lot more other cases and then some, related to pointer arithmetics as well.

The check's name would have been fine as-is now (and making it part of _ˋbugprone-sizeof-expressionˋ_ will be fine as well), because the vast majority of cases will have ˋsizeofˋ as the issue, and both ˋalignof()ˋ and ˋoffsetof()ˋ essentially scaled **with** ˋsizeofˋ internally, **AND** lets the user commit to the same bogus pattern by doing another scaling with the ˋ+ˋ/ˋ-ˋ operator.

@nicovank
> The two examples in the check documentation would not be matched with the current version of this check as they mutiply the `sizeof` expression with a constant before addition. I feel like this is also a common pattern. Can this check also catch those?

Yes, I have already added some deliberately failing tests for these last night, and I am engineering the appropriate matchers for this.

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


More information about the cfe-commits mailing list