Skip to content

Commit ab53d51

Browse files
authored
Fix or suppress clang-tidy warnings (#8254)
1 parent 5003939 commit ab53d51

File tree

28 files changed

+62
-56
lines changed

28 files changed

+62
-56
lines changed

.clang-tidy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Checks:
4545
-clang-diagnostic-#warnings,
4646
-clang-diagnostic-pedantic,
4747
clang-analyzer-*,
48+
-clang-analyzer-optin.cplusplus.UninitializedObject,
49+
-clang-analyzer-security.FloatLoopCounter,
4850
cppcoreguidelines-slicing,
4951
google-build-namespaces,
5052
google-explicit-constructor,

benchmark/src/main/native/cpp/Main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ void BM_Transform(benchmark::State& state) {
2222
auto transform = pose2 - pose1;
2323
return units::math::hypot(transform.X(), transform.Y()).value();
2424
}};
25+
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
2526
for (auto _ : state) {
2627
traveler.Solve(poses, iterations);
2728
}
@@ -33,6 +34,7 @@ void BM_Twist(benchmark::State& state) {
3334
auto twist = pose1.Log(pose2);
3435
return units::math::hypot(twist.dx, twist.dy).value();
3536
}};
37+
// NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores)
3638
for (auto _ : state) {
3739
traveler.Solve(poses, iterations);
3840
}

cscore/examples/usbcvstream/usbcvstream.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <opencv2/core/core.hpp>
66
#include <wpi/print.h>
77

8-
#include "cscore.h"
98
#include "cscore_cv.h"
109

1110
int main() {

cscore/src/main/native/cpp/cscore_c.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static O* ConvertToC(std::vector<I>&& in, int* count) {
4444
// retain vector at end of returned array
4545
alignas(T) unsigned char buf[sizeof(T)];
4646
new (buf) T(std::move(in));
47-
std::memcpy(out + size * sizeof(O), buf, sizeof(T));
47+
std::memcpy(out + size, buf, sizeof(T));
4848

4949
return out;
5050
}
@@ -392,7 +392,7 @@ void CS_FreeEvents(CS_Event* arr, int count) {
392392
// destroy vector saved at end of array
393393
using T = std::vector<cs::RawEvent>;
394394
alignas(T) unsigned char buf[sizeof(T)];
395-
std::memcpy(buf, arr + count * sizeof(CS_Event), sizeof(T));
395+
std::memcpy(buf, arr + count, sizeof(T));
396396
reinterpret_cast<T*>(buf)->~T();
397397

398398
std::free(arr);

cscore/src/main/native/windows/UsbCameraImpl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,8 +707,9 @@ void UsbCameraImpl::DeviceCacheProperty(
707707
}
708708

709709
NotifyPropertyCreated(*rawIndex, *rawPropPtr);
710-
if (perPropPtr && perIndex)
710+
if (perPropPtr && perIndex) {
711711
NotifyPropertyCreated(*perIndex, *perPropPtr);
712+
}
712713
}
713714

714715
CS_StatusValue UsbCameraImpl::DeviceProcessCommand(

glass/src/lib/native/cpp/other/PIDController.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44

55
#include "glass/other/PIDController.h"
66

7-
#include <string>
8-
97
#include <imgui.h>
108

11-
#include "glass/Context.h"
129
#include "glass/DataSource.h"
1310

1411
using namespace glass;
@@ -34,8 +31,8 @@ void glass::DisplayPIDController(PIDControllerModel* m) {
3431
[flag](const char* name, double* v,
3532
std::function<void(double)> callback) {
3633
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 4);
37-
if (ImGui::InputScalar(name, ImGuiDataType_Double, v, NULL, NULL,
38-
"%.3f", flag)) {
34+
if (ImGui::InputScalar(name, ImGuiDataType_Double, v, nullptr,
35+
nullptr, "%.3f", flag)) {
3936
callback(*v);
4037
}
4138
};

glass/src/lib/native/cpp/other/ProfiledPIDController.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44

55
#include "glass/other/ProfiledPIDController.h"
66

7-
#include <string>
8-
97
#include <imgui.h>
108

11-
#include "glass/Context.h"
129
#include "glass/DataSource.h"
1310

1411
using namespace glass;
@@ -34,8 +31,8 @@ void glass::DisplayProfiledPIDController(ProfiledPIDControllerModel* m) {
3431
[flag](const char* name, double* v,
3532
std::function<void(double)> callback) {
3633
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 4);
37-
if (ImGui::InputScalar(name, ImGuiDataType_Double, v, NULL, NULL,
38-
"%.3f", flag)) {
34+
if (ImGui::InputScalar(name, ImGuiDataType_Double, v, nullptr,
35+
nullptr, "%.3f", flag)) {
3936
callback(*v);
4037
}
4138
};

ntcore/.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Checks:
4444
-clang-diagnostic-#warnings,
4545
-clang-diagnostic-pedantic,
4646
clang-analyzer-*,
47+
-clang-analyzer-optin.cplusplus.UninitializedObject,
4748
cppcoreguidelines-slicing,
4849
google-build-namespaces,
4950
google-explicit-constructor,

ntcore/manualTests/native/client.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,17 @@
1111

1212
int main() {
1313
auto inst = nt::GetDefaultInstance();
14-
nt::AddLogger(
15-
inst,
16-
[](const nt::LogMessage& msg) {
17-
std::fputs(msg.message.c_str(), stderr);
18-
std::fputc('\n', stderr);
19-
},
20-
0, UINT_MAX);
21-
nt::StartClient(inst, "127.0.0.1", 10000);
14+
nt::AddLogger(inst, 0, UINT_MAX, [](const nt::Event& event) {
15+
std::fputs(event.GetLogMessage()->message.c_str(), stderr);
16+
std::fputc('\n', stderr);
17+
});
18+
nt::StartClient4(inst, "127.0.0.1");
2219
std::this_thread::sleep_for(std::chrono::seconds(2));
2320

2421
auto foo = nt::GetEntry(inst, "/foo");
2522
auto foo_val = nt::GetEntryValue(foo);
26-
if (foo_val && foo_val->IsDouble()) {
27-
std::printf("Got foo: %g\n", foo_val->GetDouble());
23+
if (foo_val && foo_val.IsDouble()) {
24+
std::printf("Got foo: %g\n", foo_val.GetDouble());
2825
}
2926

3027
auto bar = nt::GetEntry(inst, "/bar");

ntcore/manualTests/native/server.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,11 @@
1111

1212
int main() {
1313
auto inst = nt::GetDefaultInstance();
14-
nt::AddLogger(
15-
inst,
16-
[](const nt::LogMessage& msg) {
17-
std::fputs(msg.message.c_str(), stderr);
18-
std::fputc('\n', stderr);
19-
},
20-
0, UINT_MAX);
21-
nt::StartServer(inst, "persistent.ini", "", 10000);
14+
nt::AddLogger(inst, 0, UINT_MAX, [](const nt::Event& event) {
15+
std::fputs(event.GetLogMessage()->message.c_str(), stderr);
16+
std::fputc('\n', stderr);
17+
});
18+
nt::StartServer(inst, "persistent.ini", "", 10000, 10001);
2219
std::this_thread::sleep_for(std::chrono::seconds(1));
2320

2421
auto foo = nt::GetEntry(inst, "/foo");

0 commit comments

Comments
 (0)