Skip to content

Commit a3445ac

Browse files
committed
misc: Rename the new option to an even better version, as per review request
1 parent 298ea45 commit a3445ac

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ SizeofExpressionCheck::SizeofExpressionCheck(StringRef Name,
7171
WarnOnSizeOfPointerToAggregate(
7272
Options.get("WarnOnSizeOfPointerToAggregate", true)),
7373
WarnOnSizeOfPointer(Options.get("WarnOnSizeOfPointer", false)),
74-
WarnOnArithmeticWithDivisionBySizeOf(
75-
Options.get("WarnOnArithmeticWithDivisionBySizeOf", true)) {}
74+
WarnOnOffsetDividedBySizeOf(
75+
Options.get("WarnOnOffsetDividedBySizeOf", true)) {}
7676

7777
void SizeofExpressionCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
7878
Options.store(Opts, "WarnOnSizeOfConstant", WarnOnSizeOfConstant);
@@ -84,8 +84,8 @@ void SizeofExpressionCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
8484
Options.store(Opts, "WarnOnSizeOfPointerToAggregate",
8585
WarnOnSizeOfPointerToAggregate);
8686
Options.store(Opts, "WarnOnSizeOfPointer", WarnOnSizeOfPointer);
87-
Options.store(Opts, "WarnOnArithmeticWithDivisionBySizeOf",
88-
WarnOnArithmeticWithDivisionBySizeOf);
87+
Options.store(Opts, "WarnOnOffsetDividedBySizeOf",
88+
WarnOnOffsetDividedBySizeOf);
8989
}
9090

9191
void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
@@ -311,9 +311,8 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
311311
offsetOfExpr()))
312312
.bind("sizeof-in-ptr-arithmetic-scale-expr");
313313
const auto PtrArithmeticIntegerScaleExpr = binaryOperator(
314-
WarnOnArithmeticWithDivisionBySizeOf
315-
? binaryOperator(hasAnyOperatorName("*", "/"))
316-
: binaryOperator(hasOperatorName("*")),
314+
WarnOnOffsetDividedBySizeOf ? binaryOperator(hasAnyOperatorName("*", "/"))
315+
: binaryOperator(hasOperatorName("*")),
317316
// sizeof(...) * sizeof(...) and sizeof(...) / sizeof(...) is handled
318317
// by this check on another path.
319318
hasOperands(expr(hasType(isInteger()), unless(SizeofLikeScaleExpr)),

clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SizeofExpressionCheck : public ClangTidyCheck {
3131
const bool WarnOnSizeOfCompareToConstant;
3232
const bool WarnOnSizeOfPointerToAggregate;
3333
const bool WarnOnSizeOfPointer;
34-
const bool WarnOnArithmeticWithDivisionBySizeOf;
34+
const bool WarnOnOffsetDividedBySizeOf;
3535
};
3636

3737
} // namespace clang::tidy::bugprone

clang-tools-extra/docs/clang-tidy/checks/bugprone/sizeof-expression.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,15 @@ and the result is typically unintended, often out of bounds.
221221
``Ptr + sizeof(T)`` will offset the pointer by ``sizeof(T)`` elements,
222222
effectively exponentiating the scaling factor to the power of 2.
223223

224-
Similarly, multiplying or dividing a numeric value with the ``sizeof`` an
224+
Similarly, multiplying or dividing a numeric value with the ``sizeof`` of an
225225
element or the whole buffer is suspicious, because the dimensional connection
226226
between the numeric value and the actual ``sizeof`` result can not always be
227227
deduced.
228228
While scaling an integer up (multiplying) with ``sizeof`` is likely **always**
229229
an issue, a scaling down (division) is not always inherently dangerous, in case
230230
the developer is aware that the division happens between an appropriate number
231231
of _bytes_ and a ``sizeof`` value.
232-
Turning :option:`WarnOnArithmeticWithDivisionBySizeOf` off will restrict the
232+
Turning :option:`WarnOnOffsetDividedBySizeOf` off will restrict the
233233
warnings to the multiplication case.
234234

235235
This case also checks suspicious ``alignof`` and ``offsetof`` usages in
@@ -311,7 +311,7 @@ Options
311311
idiomatic expressions that are probably intentional and correct).
312312
This detects occurrences of CWE 467. Default is `false`.
313313

314-
.. option:: WarnOnArithmeticWithDivisionBySizeOf
314+
.. option:: WarnOnOffsetDividedBySizeOf
315315

316316
When `true`, the check will warn on pointer arithmetic where the
317317
element count is obtained from a division with ``sizeof(...)``,

clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-pointer-arithmetics-no-division.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %check_clang_tidy %s bugprone-sizeof-expression %t -- \
22
// RUN: -config='{CheckOptions: { \
3-
// RUN: bugprone-sizeof-expression.WarnOnArithmeticWithDivisionBySizeOf: false \
3+
// RUN: bugprone-sizeof-expression.WarnOnOffsetDividedBySizeOf: false \
44
// RUN: }}'
55

66
typedef __SIZE_TYPE__ size_t;

0 commit comments

Comments
 (0)