[clang-tidy] Make `P +- BS / sizeof(*P)` opt-outable in `bugprone-sizeof-expression` (#111178)
In some cases and for projects that deal with a lot of low-level buffers, a pattern often emerges that an array and its full size, not in the number of "elements" but in "bytes", are known with no syntax-level connection between the two values. To access the array elements, the pointer arithmetic involved will have to divide 'SizeInBytes' (a numeric value) with `sizeof(*Buffer)`. Since the previous patch introduced this new warning, potential false-positives were triggered from `bugprone-sizeof-expression`, as `sizeof` appeared in pointer arithmetic where integers are scaled. This patch adds a new check option, `WarnOnOffsetDividedBySizeOf`, which allows users to opt out of warning about the division case. In arbitrary projects, it might still be worthwhile to get these warnings until an opt-out from the detection of scaling issues, especially if a project might not be using low-level buffers intensively.
Loading
Please register or sign in to comment