Skip to content

Commit fc17142

Browse files
committed
Update clang-tidy
Fix a bunch of minor issues, ignore others. We use a lot of global variables. Enabling a check will hopefully make sure we don't add more. Change-Id: Ie76053d4afc95a5372b70b2fb768be464468cec0 Signed-off-by: Ed Tanous <[email protected]>
1 parent a3ca14a commit fc17142

9 files changed

+66
-3
lines changed

.clang-tidy

+42
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,24 @@ Checks: '
33
boost-use-to-string,
44
bugprone-argument-comment,
55
bugprone-assert-side-effect,
6+
bugprone-assignment-in-if-condition,
67
bugprone-bad-signal-to-kill-thread,
78
bugprone-bool-pointer-implicit-conversion,
89
bugprone-branch-clone,
10+
bugprone-casting-through-void,
11+
bugprone-chained-comparison,
12+
bugprone-compare-pointer-to-member-virtual-function,
913
bugprone-copy-constructor-init,
1014
bugprone-dangling-handle,
1115
bugprone-dynamic-static-initializers,
16+
bugprone-empty-catch,
1217
bugprone-fold-init-type,
1318
bugprone-forward-declaration-namespace,
1419
bugprone-forwarding-reference-overload,
1520
bugprone-implicit-widening-of-multiplication-result,
1621
bugprone-inaccurate-erase,
22+
bugprone-inc-dec-in-conditions,
23+
bugprone-incorrect-enable-if,
1724
bugprone-incorrect-roundings,
1825
bugprone-infinite-loop,
1926
bugprone-integer-division,
@@ -24,35 +31,49 @@ bugprone-misplaced-operator-in-strlen-in-alloc,
2431
bugprone-misplaced-pointer-arithmetic-in-alloc,
2532
bugprone-misplaced-widening-cast,
2633
bugprone-move-forwarding-reference,
34+
bugprone-multi-level-implicit-pointer-conversion,
35+
bugprone-multiple-new-in-one-expression,
2736
bugprone-multiple-statement-macro,
2837
bugprone-no-escape,
38+
bugprone-non-zero-enum-to-bool-conversion,
2939
bugprone-not-null-terminated-result,
40+
bugprone-optional-value-conversion,
3041
bugprone-parent-virtual-call,
3142
bugprone-posix-return,
3243
bugprone-redundant-branch-condition,
3344
bugprone-reserved-identifier,
45+
bugprone-shared-ptr-array-mismatch,
3446
bugprone-signal-handler,
3547
bugprone-signed-char-misuse,
3648
bugprone-sizeof-container,
3749
bugprone-sizeof-expression,
3850
bugprone-spuriously-wake-up-functions,
51+
bugprone-standalone-empty,
3952
bugprone-string-constructor,
4053
bugprone-string-integer-assignment,
4154
bugprone-string-literal-with-embedded-nul,
55+
bugprone-stringview-nullptr,
4256
bugprone-suspicious-enum-usage,
4357
bugprone-suspicious-include,
58+
bugprone-suspicious-memory-comparison,
4459
bugprone-suspicious-memset-usage,
4560
bugprone-suspicious-missing-comma,
61+
bugprone-suspicious-realloc-usage,
4662
bugprone-suspicious-semicolon,
4763
bugprone-suspicious-string-compare,
4864
bugprone-swapped-arguments,
65+
bugprone-switch-missing-default-case,
4966
bugprone-terminating-continue,
5067
bugprone-throw-keyword-missing,
5168
bugprone-too-small-loop-variable,
69+
bugprone-unchecked-optional-access,
5270
bugprone-undefined-memory-manipulation,
5371
bugprone-undelegated-constructor,
5472
bugprone-unhandled-exception-at-new,
5573
bugprone-unhandled-self-assignment,
74+
bugprone-unique-ptr-array-mismatch,
75+
bugprone-unsafe-functions,
76+
bugprone-unused-local-non-trivial-variable,
5677
bugprone-unused-raii,
5778
bugprone-unused-return-value,
5879
bugprone-use-after-move,
@@ -89,8 +110,10 @@ cert-pos44-c,
89110
cert-pos47-c,
90111
cert-sig30-c,
91112
cert-str34-c,
113+
clang-analyzer-apiModeling.Errno,
92114
clang-analyzer-apiModeling.StdCLibraryFunctions,
93115
clang-analyzer-apiModeling.TrustNonnull,
116+
clang-analyzer-apiModeling.TrustReturnsNonnull,
94117
clang-analyzer-apiModeling.google.GTest,
95118
clang-analyzer-apiModeling.llvm.CastValue,
96119
clang-analyzer-apiModeling.llvm.ReturnValue,
@@ -111,6 +134,7 @@ clang-analyzer-core.uninitialized.ArraySubscript,
111134
clang-analyzer-core.uninitialized.Assign,
112135
clang-analyzer-core.uninitialized.Branch,
113136
clang-analyzer-core.uninitialized.CapturedBlockVariable,
137+
clang-analyzer-core.uninitialized.NewArraySize,
114138
clang-analyzer-core.uninitialized.UndefReturn,
115139
clang-analyzer-cplusplus.InnerPointer,
116140
clang-analyzer-cplusplus.Move,
@@ -120,6 +144,7 @@ clang-analyzer-cplusplus.PlacementNew,
120144
clang-analyzer-cplusplus.PureVirtualCall,
121145
clang-analyzer-cplusplus.SelfAssignment,
122146
clang-analyzer-cplusplus.SmartPtrModeling,
147+
clang-analyzer-cplusplus.StringChecker,
123148
clang-analyzer-cplusplus.VirtualCallModeling,
124149
clang-analyzer-deadcode.DeadStores,
125150
clang-analyzer-fuchsia.HandleChecker,
@@ -199,8 +224,10 @@ clang-analyzer-valist.Unterminated,
199224
clang-analyzer-valist.ValistBase,
200225
clang-analyzer-webkit.NoUncountedMemberChecker,
201226
clang-analyzer-webkit.RefCntblBaseVirtualDtor,
227+
clang-analyzer-webkit.UncountedLambdaCapturesChecker,
202228
cppcoreguidelines-avoid-c-arrays,
203229
cppcoreguidelines-avoid-goto,
230+
cppcoreguidelines-avoid-non-const-global-variables,
204231
cppcoreguidelines-c-copy-assignment-signature,
205232
cppcoreguidelines-explicit-virtual-functions,
206233
cppcoreguidelines-init-variables,
@@ -218,12 +245,20 @@ cppcoreguidelines-pro-type-static-cast-downcast,
218245
cppcoreguidelines-pro-type-union-access,
219246
cppcoreguidelines-slicing,
220247
google-explicit-constructor,
248+
misc-coroutine-hostile-raii,
249+
misc-header-include-cycle,
250+
misc-misleading-bidirectional,
251+
misc-misleading-identifier,
221252
misc-misplaced-const,
253+
misc-new-delete-overloads,
254+
misc-non-copyable-objects,
222255
misc-redundant-expression,
223256
misc-static-assert,
224257
misc-throw-by-value-catch-by-reference,
225258
misc-unconventional-assign-operator,
226259
misc-uniqueptr-reset-release,
260+
misc-unused-alias-decls,
261+
misc-unused-parameters,
227262
misc-unused-using-decls,
228263
modernize-avoid-bind,
229264
modernize-deprecated-headers,
@@ -265,8 +300,11 @@ performance-type-promotion-in-math-fn,
265300
performance-unnecessary-copy-initialization,
266301
performance-unnecessary-value-param,
267302
readability-avoid-const-params-in-decls,
303+
readability-avoid-nested-conditional-operator,
268304
readability-braces-around-statements,
269305
readability-const-return-type,
306+
readability-container-contains,
307+
readability-container-data-pointer,
270308
readability-container-size-empty,
271309
readability-convert-member-functions-to-static,
272310
readability-delete-null-pointer,
@@ -287,6 +325,7 @@ readability-redundant-access-specifiers,
287325
readability-redundant-control-flow,
288326
readability-redundant-declaration,
289327
readability-redundant-function-ptr-dereference,
328+
readability-redundant-inline-specifier,
290329
readability-redundant-member-init,
291330
readability-redundant-preprocessor,
292331
readability-redundant-smartptr-get,
@@ -300,6 +339,7 @@ readability-string-compare,
300339
readability-suspicious-call-argument,
301340
readability-uniqueptr-delete-release,
302341
readability-uppercase-literal-suffix'
342+
303343
WarningsAsErrors: '*'
304344
HeaderFilterRegex: '.*'
305345
CheckOptions:
@@ -309,3 +349,5 @@ CheckOptions:
309349
- { key: readability-identifier-naming.ParameterCase, value: camelBack }
310350
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
311351
- { key: readability-identifier-naming.StructCase, value: CamelCase }
352+
- { key: cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreUnnamedParams, value: true }
353+
- { key: misc-include-cleaner.IgnoreHeaders, value: ((nlohmann/json_fwd.hpp)|(boost/.*/src.hpp)|(boost/.*/detail/.*)|(nlohmann/detail/.*)|(stdio.h)|(ranges)|(bits/chrono.h)|(boost/system/error_code.hpp)) }

src/entity_manager.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ using JsonVariantType =
6868
int64_t, uint64_t, double, int32_t, uint32_t, int16_t,
6969
uint16_t, uint8_t, bool>;
7070

71+
// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
7172
// store reference to all interfaces so we can destroy them later
7273
boost::container::flat_map<
7374
std::string, std::vector<std::weak_ptr<sdbusplus::asio::dbus_interface>>>
@@ -79,6 +80,7 @@ nlohmann::json lastJson;
7980
Topology topology;
8081

8182
boost::asio::io_context io;
83+
// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)
8284

8385
const std::regex illegalDbusPathRegex("[^A-Za-z0-9_.]");
8486
const std::regex illegalDbusMemberRegex("[^A-Za-z0-9_]");

src/fru_device.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ const static constexpr char* baseboardFruLocation =
7272

7373
const static constexpr char* i2CDevLocation = "/dev";
7474

75+
// TODO Refactor these to not be globals
76+
// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
7577
static boost::container::flat_map<size_t, std::optional<std::set<size_t>>>
7678
busBlocklist;
7779
struct FindDevicesWithCallback;
@@ -84,6 +86,7 @@ static boost::container::flat_map<size_t, std::set<size_t>> failedAddresses;
8486
static boost::container::flat_map<size_t, std::set<size_t>> fruAddresses;
8587

8688
boost::asio::io_context io;
89+
// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)
8790

8891
bool updateFRUProperty(
8992
const std::string& updatePropertyReq, uint32_t bus, uint32_t address,
@@ -621,13 +624,13 @@ void loadBlocklist(const char* path)
621624
auto addresses =
622625
addressData.get<std::set<std::string_view>>();
623626

624-
busBlocklist[bus].emplace();
627+
auto& block = busBlocklist[bus].emplace();
625628
for (const auto& address : addresses)
626629
{
627630
size_t addressInt = 0;
628631
std::from_chars(address.begin() + 2, address.end(),
629632
addressInt, 16);
630-
busBlocklist[bus]->insert(addressInt);
633+
block.insert(addressInt);
631634
}
632635
}
633636
else
@@ -1416,6 +1419,7 @@ int main()
14161419
case IN_CREATE:
14171420
case IN_MOVED_TO:
14181421
case IN_DELETE:
1422+
{
14191423
std::string_view name(&iEvent->name[0], iEvent->len);
14201424
if (boost::starts_with(name, "i2c"))
14211425
{
@@ -1438,6 +1442,10 @@ int main()
14381442
unknownBusObjectCount, powerIsOn,
14391443
objServer, systemBus);
14401444
}
1445+
}
1446+
break;
1447+
default:
1448+
break;
14411449
}
14421450
index += sizeof(inotify_event) + iEvent->len;
14431451
}

src/fru_utils.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ std::pair<DecodeState, std::string>
191191
}
192192
}
193193
break;
194+
195+
default:
196+
{
197+
return make_pair(DecodeState::err, value);
198+
}
194199
}
195200

196201
return make_pair(DecodeState::ok, value);

src/fru_utils.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ constexpr size_t fruBlockSize = 8;
3838
using DeviceMap = boost::container::flat_map<int, std::vector<uint8_t>>;
3939
using BusMap = boost::container::flat_map<int, std::shared_ptr<DeviceMap>>;
4040

41+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
4142
inline BusMap busMap;
4243

4344
enum class DecodeState

src/overlay.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ constexpr const char* muxSymlinkDir = "/dev/i2c-mux";
4141

4242
constexpr const bool debug = false;
4343

44-
std::regex illegalNameRegex("[^A-Za-z0-9_]");
44+
const std::regex illegalNameRegex("[^A-Za-z0-9_]");
4545

4646
// helper function to make json types into string
4747
std::string jsonToString(const nlohmann::json& in)

src/perform_scan.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424
#include <charconv>
2525

2626
/* Hacks from splitting entity_manager.cpp */
27+
// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
2728
extern std::shared_ptr<sdbusplus::asio::connection> systemBus;
2829
extern nlohmann::json lastJson;
2930
extern void
3031
propertiesChangedCallback(nlohmann::json& systemConfiguration,
3132
sdbusplus::asio::object_server& objServer);
33+
// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)
3234

3335
using GetSubTreeType = std::vector<
3436
std::pair<std::string,

src/utils.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
constexpr const char* templateChar = "$";
4343

4444
namespace fs = std::filesystem;
45+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
4546
static bool powerStatusOn = false;
47+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
4648
static std::unique_ptr<sdbusplus::bus::match_t> powerMatch = nullptr;
4749

4850
bool findFiles(const fs::path& dirPath, const std::string& matchString,

src/utils.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ constexpr const char* configurationOutDir = "/var/configuration/";
3030
constexpr const char* versionHashFile = "/var/configuration/version";
3131
constexpr const char* versionFile = "/etc/os-release";
3232

33+
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
3334
extern boost::asio::io_context io;
3435

3536
using DBusValueVariant =

0 commit comments

Comments
 (0)