Skip to content

Commit 292752b

Browse files
committed
Rename tool
1 parent 357350e commit 292752b

File tree

9 files changed

+108
-23
lines changed

9 files changed

+108
-23
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
#include "TooSmallLoopVariableCheck.h"
8787
#include "UncheckedOptionalAccessCheck.h"
8888
#include "UndefinedMemoryManipulationCheck.h"
89-
#include "UndefinedSprintfOverlapCheck.h"
89+
#include "SprintfArgumentOverlapCheck.h"
9090
#include "UndelegatedConstructorCheck.h"
9191
#include "UnhandledExceptionAtNewCheck.h"
9292
#include "UnhandledSelfAssignmentCheck.h"
@@ -249,8 +249,8 @@ class BugproneModule : public ClangTidyModule {
249249
"bugprone-unchecked-optional-access");
250250
CheckFactories.registerCheck<UndefinedMemoryManipulationCheck>(
251251
"bugprone-undefined-memory-manipulation");
252-
CheckFactories.registerCheck<UndefinedSprintfOverlapCheck>(
253-
"bugprone-undefined-sprintf-overlap");
252+
CheckFactories.registerCheck<SprintfArgumentOverlapCheck>(
253+
"bugprone-sprintf-argument-overlap");
254254
CheckFactories.registerCheck<UndelegatedConstructorCheck>(
255255
"bugprone-undelegated-constructor");
256256
CheckFactories.registerCheck<UnhandledSelfAssignmentCheck>(

clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ add_clang_library(clangTidyBugproneModule STATIC
8383
TooSmallLoopVariableCheck.cpp
8484
UncheckedOptionalAccessCheck.cpp
8585
UndefinedMemoryManipulationCheck.cpp
86-
UndefinedSprintfOverlapCheck.cpp
86+
SprintfArgumentOverlapCheck.cpp
8787
UndelegatedConstructorCheck.cpp
8888
UnhandledExceptionAtNewCheck.cpp
8989
UnhandledSelfAssignmentCheck.cpp

clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.cpp renamed to clang-tools-extra/clang-tidy/bugprone/SprintfArgumentOverlapCheck.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
//===--- UndefinedSprintfOverlapCheck.cpp - clang-tidy --------------------===//
1+
//===--- SprintfArgumentOverlapCheck.cpp - clang-tidy --------------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "UndefinedSprintfOverlapCheck.h"
9+
#include "SprintfArgumentOverlapCheck.h"
1010
#include "../utils/ASTUtils.h"
1111
#include "clang/ASTMatchers/ASTMatchFinder.h"
1212
#include "clang/Lex/Lexer.h"
@@ -48,12 +48,12 @@ AST_MATCHER_P(CallExpr, forEachArgument, ast_matchers::internal::Matcher<Expr>,
4848
return Matched;
4949
}
5050

51-
UndefinedSprintfOverlapCheck::UndefinedSprintfOverlapCheck(
51+
SprintfArgumentOverlapCheck::SprintfArgumentOverlapCheck(
5252
StringRef Name, ClangTidyContext *Context)
5353
: ClangTidyCheck(Name, Context),
5454
SprintfRegex(Options.get("SprintfFunction", "(::std)?::sn?printf")) {}
5555

56-
void UndefinedSprintfOverlapCheck::registerMatchers(MatchFinder *Finder) {
56+
void SprintfArgumentOverlapCheck::registerMatchers(MatchFinder *Finder) {
5757
Finder->addMatcher(
5858
callExpr(callee(functionDecl(matchesName(SprintfRegex)).bind("decl")),
5959
hasArgument(0, expr().bind("firstArgExpr")),
@@ -63,7 +63,7 @@ void UndefinedSprintfOverlapCheck::registerMatchers(MatchFinder *Finder) {
6363
this);
6464
}
6565

66-
void UndefinedSprintfOverlapCheck::check(
66+
void SprintfArgumentOverlapCheck::check(
6767
const MatchFinder::MatchResult &Result) {
6868
const auto *FirstArg = Result.Nodes.getNodeAs<Expr>("firstArgExpr");
6969
const auto *OtherArg = Result.Nodes.getNodeAs<Expr>("otherArgExpr");
@@ -97,7 +97,7 @@ void UndefinedSprintfOverlapCheck::check(
9797
<< OtherArg->getSourceRange();
9898
}
9999

100-
void UndefinedSprintfOverlapCheck::storeOptions(
100+
void SprintfArgumentOverlapCheck::storeOptions(
101101
ClangTidyOptions::OptionMap &Opts) {
102102
Options.store(Opts, "SprintfRegex", SprintfRegex);
103103
}

clang-tools-extra/clang-tidy/bugprone/UndefinedSprintfOverlapCheck.h renamed to clang-tools-extra/clang-tidy/bugprone/SprintfArgumentOverlapCheck.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
//===--- UndefinedSprintfOverlapCheck.h - clang-tidy ------------*- C++ -*-===//
1+
//===--- SprintfArgumentOverlapCheck.h - clang-tidy -------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNDEFINEDSPRINTFOVERLAPCHECK_H
10-
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNDEFINEDSPRINTFOVERLAPCHECK_H
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SPRINTFARGUMENTOVERLAPCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SPRINTFARGUMENTOVERLAPCHECK_H
1111

1212
#include "../ClangTidyCheck.h"
1313

@@ -17,10 +17,10 @@ namespace clang::tidy::bugprone {
1717
/// the destination buffer (the first argument).
1818
///
1919
/// For the user-facing documentation see:
20-
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/undefined-sprintf-overlap.html
21-
class UndefinedSprintfOverlapCheck : public ClangTidyCheck {
20+
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/sprintf-argument-overlap.html
21+
class SprintfArgumentOverlapCheck : public ClangTidyCheck {
2222
public:
23-
UndefinedSprintfOverlapCheck(StringRef Name, ClangTidyContext *Context);
23+
SprintfArgumentOverlapCheck(StringRef Name, ClangTidyContext *Context);
2424
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
2525
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
2626
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
@@ -37,4 +37,4 @@ class UndefinedSprintfOverlapCheck : public ClangTidyCheck {
3737

3838
} // namespace clang::tidy::bugprone
3939

40-
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNDEFINEDSPRINTFOVERLAPCHECK_H
40+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SPRINTFARGUMENTOVERLAPCHECK_H

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ New checks
157157
Gives warnings for tagged unions, where the number of tags is
158158
different from the number of data members inside the union.
159159

160-
- New :doc:`bugprone-undefined-sprintf-overlap
161-
<clang-tidy/checks/bugprone/undefined-sprintf-overlap>` check.
160+
- New :doc:`bugprone-sprintf-argument-overlap
161+
<clang-tidy/checks/bugprone/sprintf-argument-overlap>` check.
162162

163163
Warns if any arguments to the ``sprintf`` family of functions overlap with the
164164
first argument.

clang-tools-extra/docs/clang-tidy/checks/bugprone/undefined-sprintf-overlap.rst renamed to clang-tools-extra/docs/clang-tidy/checks/bugprone/sprintf-argument-overlap.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
.. title:: clang-tidy - bugprone-undefined-sprintf-overlap
1+
.. title:: clang-tidy - bugprone-sprintf-argument-overlap
22

3-
bugprone-undefined-sprintf-overlap
4-
==================================
3+
bugprone-sprintf-argument-overlap
4+
=================================
55

66
Warns if any arguments to the ``sprintf`` family of functions overlap with the
77
destination buffer (the first argument).

clang-tools-extra/docs/clang-tidy/checks/list.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Clang-Tidy Checks
154154
:doc:`bugprone-too-small-loop-variable <bugprone/too-small-loop-variable>`,
155155
:doc:`bugprone-unchecked-optional-access <bugprone/unchecked-optional-access>`,
156156
:doc:`bugprone-undefined-memory-manipulation <bugprone/undefined-memory-manipulation>`,
157-
:doc:`bugprone-undefined-sprintf-overlap <bugprone/undefined-sprintf-overlap>`,
157+
:doc:`bugprone-sprintf-argument-overlap <bugprone/sprintf-argument-overlap>`,
158158
:doc:`bugprone-undelegated-constructor <bugprone/undelegated-constructor>`,
159159
:doc:`bugprone-unhandled-exception-at-new <bugprone/unhandled-exception-at-new>`,
160160
:doc:`bugprone-unhandled-self-assignment <bugprone/unhandled-self-assignment>`,
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// RUN: %check_clang_tidy %s bugprone-sprintf-argument-overlap %t
2+
3+
using size_t = decltype(sizeof(int));
4+
5+
extern "C" int sprintf(char *s, const char *format, ...);
6+
extern "C" int snprintf(char *s, size_t n, const char *format, ...);
7+
8+
namespace std {
9+
int snprintf(char *s, size_t n, const char *format, ...);
10+
}
11+
12+
struct st_t {
13+
char buf[10];
14+
char buf2[10];
15+
};
16+
17+
struct st2_t {
18+
st_t inner;
19+
};
20+
21+
struct st3_t {
22+
st2_t inner;
23+
};
24+
25+
void first_arg_overlaps() {
26+
char buf[10];
27+
sprintf(buf, "%s", buf);
28+
// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: the 2nd argument in 'sprintf' overlaps the 1st argument, which is undefined behavior [bugprone-sprintf-argument-overlap]
29+
snprintf(buf, sizeof(buf), "%s", buf);
30+
// CHECK-MESSAGES: :[[@LINE-1]]:36: warning: the 3rd argument in 'snprintf' overlaps the 1st argument, which is undefined behavior [bugprone-sprintf-argument-overlap]
31+
std::snprintf(buf, sizeof(buf), "%s", buf);
32+
// CHECK-MESSAGES: :[[@LINE-1]]:41: warning: the 3rd argument in 'snprintf' overlaps the 1st argument, which is undefined behavior [bugprone-sprintf-argument-overlap]
33+
34+
char* c = &buf[0];
35+
sprintf(c, "%s", c);
36+
// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: the 2nd argument in 'sprintf' overlaps the 1st argument, which is undefined behavior [bugprone-sprintf-argument-overlap]
37+
snprintf(c, sizeof(buf), "%s", c);
38+
// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: the 3rd argument in 'snprintf' overlaps the 1st argument, which is undefined behavior [bugprone-sprintf-argument-overlap]
39+
40+
snprintf(c, sizeof(buf), "%s%s", c, c);
41+
// CHECK-MESSAGES: :[[@LINE-1]]:36: warning: the 3rd argument in 'snprintf' overlaps the 1st argument, which is undefined behavior [bugprone-sprintf-argument-overlap]
42+
// CHECK-MESSAGES: :[[@LINE-2]]:39: warning: the 4th argument in 'snprintf' overlaps the 1st argument, which is undefined behavior [bugprone-sprintf-argument-overlap]
43+
44+
char buf2[10];
45+
sprintf(buf, "%s", buf2);
46+
sprintf(buf, "%s", buf2, buf);
47+
// CHECK-MESSAGES: :[[@LINE-1]]:28: warning: the 3rd argument in 'sprintf' overlaps the 1st argument, which is undefined behavior [bugprone-sprintf-argument-overlap]
48+
49+
st_t st1, st2;
50+
sprintf(st1.buf, "%s", st1.buf);
51+
// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: the 2nd argument in 'sprintf' overlaps the 1st argument, which is undefined behavior [bugprone-sprintf-argument-overlap]
52+
sprintf(st1.buf, "%s", st1.buf2);
53+
sprintf(st1.buf, "%s", st2.buf);
54+
55+
st3_t st3;
56+
sprintf(st3.inner.inner.buf, "%s", st3.inner.inner.buf);
57+
// CHECK-MESSAGES: :[[@LINE-1]]:38: warning: the 2nd argument in 'sprintf' overlaps the 1st argument, which is undefined behavior [bugprone-sprintf-argument-overlap]
58+
sprintf((st3.inner.inner.buf), "%s", st3.inner.inner.buf);
59+
// CHECK-MESSAGES: :[[@LINE-1]]:40: warning: the 2nd argument in 'sprintf' overlaps the 1st argument, which is undefined behavior [bugprone-sprintf-argument-overlap]
60+
61+
st_t* stp;
62+
sprintf(stp->buf, "%s", stp->buf);
63+
// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: the 2nd argument in 'sprintf' overlaps the 1st argument, which is undefined behavior [bugprone-sprintf-argument-overlap]
64+
sprintf((stp->buf), "%s", stp->buf);
65+
// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: the 2nd argument in 'sprintf' overlaps the 1st argument, which is undefined behavior [bugprone-sprintf-argument-overlap]
66+
stp = &st1;
67+
sprintf(stp->buf, "%s", st1.buf);
68+
69+
char bufs[10][10];
70+
sprintf(bufs[1], "%s", bufs[1]);
71+
// CHECK-MESSAGES: :[[@LINE-1]]:26: warning: the 2nd argument in 'sprintf' overlaps the 1st argument, which is undefined behavior [bugprone-sprintf-argument-overlap]
72+
sprintf(bufs[0], "%s", bufs[1]);
73+
74+
char bufss[10][10][10];
75+
sprintf(bufss[0][1], "%s", bufss[0][1]);
76+
// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: the 2nd argument in 'sprintf' overlaps the 1st argument, which is undefined behavior [bugprone-sprintf-argument-overlap]
77+
78+
sprintf(bufss[0][0], "%s", bufss[0][1]);
79+
80+
int i = 0;
81+
sprintf(bufss[0][++i], "%s", bufss[0][++i]);
82+
}

clang-tools-extra/test/clang-tidy/checkers/bugprone/undefined-sprintf-overlap.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ void first_arg_overlaps() {
3030
// CHECK-MESSAGES: :[[@LINE-1]]:36: warning: the 3rd argument in 'snprintf' overlaps the 1st argument, which is undefined behavior [bugprone-undefined-sprintf-overlap]
3131
std::snprintf(buf, sizeof(buf), "%s", buf);
3232
// CHECK-MESSAGES: :[[@LINE-1]]:41: warning: the 3rd argument in 'snprintf' overlaps the 1st argument, which is undefined behavior [bugprone-undefined-sprintf-overlap]
33+
sprintf(buf+1, "%s", (buf+1));
34+
// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: the 2nd argument in 'sprintf' overlaps the 1st argument, which is undefined behavior [bugprone-undefined-sprintf-overlap]
35+
sprintf(buf+1, "%s", buf+2);
3336

3437
char* c = &buf[0];
3538
sprintf(c, "%s", c);

0 commit comments

Comments
 (0)