Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang-tidy] Improve sizeof(pointer) handling in bugprone-sizeof-expression #94356

Merged
merged 7 commits into from
Jun 11, 2024
6 changes: 6 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ Changes in existing checks
<clang-tidy/checks/bugprone/optional-value-conversion>` check by eliminating
false positives resulting from use of optionals in unevaluated context.

- Improved :doc:`bugprone-sizeof-expression
<clang-tidy/checks/bugprone/sizeof-expression>` check by eliminating some
false positives and adding a new (off-by-default) option
``WarnOnSizeOfPointer`` that reports all ``sizeof(pointer)`` expressions
NagyDonat marked this conversation as resolved.
Show resolved Hide resolved
(except for a few that are idiomatic).

- Improved :doc:`bugprone-suspicious-include
<clang-tidy/checks/bugprone/suspicious-include>` check by replacing the local
options `HeaderFileExtensions` and `ImplementationFileExtensions` by the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,15 @@ Options

.. option:: WarnOnSizeOfPointerToAggregate

When `true`, the check will warn on an expression like
``sizeof(expr)`` where the expression is a pointer
to aggregate. Default is `true`.
When `true`, the check will warn when the argument of ``sizeof`` is either a
pointer-to-aggregate type, an expression returning a pointer-to-aggregate
value or an expression that returns a pointer from an array-to-pointer
conversion (that may be implicit or explicit, for example ``array + 2`` or
``(int *)array``). Default is `true`.
Comment on lines +193 to +197
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also added a proper description for WarnOnSizeOfPointerToAggregate, because the old one was very vague and didn't explain the (somewhat complex) effects that are handled here.


.. option:: WarnOnSizeOfPointer

When `true`, the check will warn on an expression like ``sizeof(expr)``
where the expression is a pointer. Default is `false`.
When `true`, the check will report all expressions where the argument of
``sizeof`` is an expression that produces a pointer (except for a few
idiomatic expressions that are probably intentional and correct).
This detects occurrences of CWE 467. Default is `false`.
Loading