Skip to content

Commit 2d4c8dd

Browse files
authored
[clang-tidy] autofix cppcoreguidelines (google#1932)
* [clang-tidy] autofix cppcoreguidelines * better than automation maybe
1 parent f8db7f6 commit 2d4c8dd

10 files changed

Lines changed: 28 additions & 28 deletions

include/benchmark/benchmark.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1692,7 +1692,7 @@ class BENCHMARK_EXPORT BenchmarkReporter {
16921692
CPUInfo const& cpu_info;
16931693
SystemInfo const& sys_info;
16941694
// The number of chars in the longest benchmark name.
1695-
size_t name_field_width;
1695+
size_t name_field_width = 0;
16961696
static const char* executable_name;
16971697
Context();
16981698
};

src/benchmark_runner.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ IterationCount ComputeIters(const benchmark::internal::BenchmarkInstance& b,
186186
} // end namespace
187187

188188
BenchTimeType ParseBenchMinTime(const std::string& value) {
189-
BenchTimeType ret;
189+
BenchTimeType ret = {};
190190

191191
if (value.empty()) {
192192
ret.tag = BenchTimeType::TIME;
@@ -195,7 +195,7 @@ BenchTimeType ParseBenchMinTime(const std::string& value) {
195195
}
196196

197197
if (value.back() == 'x') {
198-
char* p_end;
198+
char* p_end = nullptr;
199199
// Reset errno before it's changed by strtol.
200200
errno = 0;
201201
IterationCount num_iters = std::strtol(value.c_str(), &p_end, 10);
@@ -217,7 +217,7 @@ BenchTimeType ParseBenchMinTime(const std::string& value) {
217217
"Eg., `30s` for 30-seconds.";
218218
}
219219

220-
char* p_end;
220+
char* p_end = nullptr;
221221
// Reset errno before it's changed by strtod.
222222
errno = 0;
223223
double min_time = std::strtod(value.c_str(), &p_end);

src/benchmark_runner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct RunResults {
3838
};
3939

4040
struct BENCHMARK_EXPORT BenchTimeType {
41-
enum { ITERS, TIME } tag;
41+
enum { UNSPECIFIED, ITERS, TIME } tag;
4242
union {
4343
IterationCount iters;
4444
double time;

src/string_util.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ std::string ExponentToPrefix(int64_t exponent, bool iec) {
105105
std::string ToBinaryStringFullySpecified(double value, int precision,
106106
Counter::OneK one_k) {
107107
std::string mantissa;
108-
int64_t exponent;
108+
int64_t exponent = 0;
109109
ToExponentAndMantissa(value, precision,
110110
one_k == Counter::kIs1024 ? 1024.0 : 1000.0, &mantissa,
111111
&exponent);
@@ -119,7 +119,7 @@ std::string StrFormatImp(const char* msg, va_list args) {
119119

120120
// TODO(ericwf): use std::array for first attempt to avoid one memory
121121
// allocation guess what the size might be
122-
std::array<char, 256> local_buff;
122+
std::array<char, 256> local_buff = {};
123123

124124
// 2015-10-08: vsnprintf is used instead of snd::vsnprintf due to a limitation
125125
// in the android-ndk

src/sysinfo.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ int CountSetBitsInCPUMap(std::string val) {
252252
CPUMask mask(benchmark::stoul(part, nullptr, 16));
253253
return static_cast<int>(mask.count());
254254
};
255-
std::size_t pos;
255+
std::size_t pos = 0;
256256
int total = 0;
257257
while ((pos = val.find(',')) != std::string::npos) {
258258
total += CountBits(val.substr(0, pos));
@@ -587,7 +587,7 @@ class ThreadAffinityGuard final {
587587
private:
588588
bool SetAffinity() {
589589
#if defined(BENCHMARK_HAS_PTHREAD_AFFINITY)
590-
int ret;
590+
int ret = 0;
591591
self = pthread_self();
592592
ret = pthread_getaffinity_np(self, sizeof(previous_affinity),
593593
&previous_affinity);
@@ -627,8 +627,8 @@ class ThreadAffinityGuard final {
627627
}
628628

629629
#if defined(BENCHMARK_HAS_PTHREAD_AFFINITY)
630-
pthread_t self;
631-
cpu_set_t previous_affinity;
630+
pthread_t self{};
631+
cpu_set_t previous_affinity{};
632632
#elif defined(BENCHMARK_OS_WINDOWS_WIN32)
633633
HANDLE self;
634634
DWORD_PTR previous_affinity;
@@ -642,7 +642,7 @@ double GetCPUCyclesPerSecond(CPUInfo::Scaling scaling) {
642642
(void)scaling;
643643

644644
#if defined BENCHMARK_OS_LINUX || defined BENCHMARK_OS_CYGWIN
645-
long freq;
645+
long freq = 0;
646646

647647
// If the kernel is exporting the tsc frequency use that. There are issues
648648
// where cpuinfo_max_freq cannot be relied on because the BIOS may be

src/timers.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ double ProcessCPUUsage() {
143143
#elif defined(CLOCK_PROCESS_CPUTIME_ID) && !defined(BENCHMARK_OS_MACOSX)
144144
// FIXME We want to use clock_gettime, but its not available in MacOS 10.11.
145145
// See https://github.com/google/benchmark/pull/292
146-
struct timespec spec;
146+
struct timespec spec {};
147147
if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &spec) == 0) {
148148
return MakeTime(spec);
149149
}
@@ -200,7 +200,7 @@ double ThreadCPUUsage() {
200200
if (getrusage(RUSAGE_LWP, &ru) == 0) return MakeTime(ru);
201201
DiagnoseAndExit("getrusage(RUSAGE_LWP, ...) failed");
202202
#elif defined(CLOCK_THREAD_CPUTIME_ID)
203-
struct timespec ts;
203+
struct timespec ts {};
204204
if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts) == 0) {
205205
return MakeTime(ts);
206206
}
@@ -217,9 +217,9 @@ std::string LocalDateTimeString() {
217217
const std::size_t kTzOffsetLen = 6;
218218
const std::size_t kTimestampLen = 19;
219219

220-
std::size_t tz_len;
221-
std::size_t timestamp_len;
222-
long int offset_minutes;
220+
std::size_t tz_len = 0;
221+
std::size_t timestamp_len = 0;
222+
long int offset_minutes = 0;
223223
char tz_offset_sign = '+';
224224
// tz_offset is set in one of three ways:
225225
// * strftime with %z - This either returns empty or the ISO 8601 time. The
@@ -239,7 +239,7 @@ std::string LocalDateTimeString() {
239239
#if defined(BENCHMARK_OS_WINDOWS)
240240
std::tm* timeinfo_p = ::localtime(&now);
241241
#else
242-
std::tm timeinfo;
242+
std::tm timeinfo{};
243243
std::tm* timeinfo_p = &timeinfo;
244244
::localtime_r(&now, &timeinfo);
245245
#endif

test/benchmark_min_time_flag_iters_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ namespace {
1313

1414
class TestReporter : public benchmark::ConsoleReporter {
1515
public:
16-
virtual bool ReportContext(const Context& context) override {
16+
bool ReportContext(const Context& context) override {
1717
return ConsoleReporter::ReportContext(context);
1818
};
1919

20-
virtual void ReportRuns(const std::vector<Run>& report) override {
20+
void ReportRuns(const std::vector<Run>& report) override {
2121
assert(report.size() == 1);
2222
iter_nums_.push_back(report[0].iterations);
2323
ConsoleReporter::ReportRuns(report);
2424
};
2525

2626
TestReporter() {}
2727

28-
virtual ~TestReporter() {}
28+
~TestReporter() override {}
2929

3030
const std::vector<benchmark::IterationCount>& GetIters() const {
3131
return iter_nums_;

test/benchmark_min_time_flag_time_test.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ typedef int64_t IterationCount;
1919

2020
class TestReporter : public benchmark::ConsoleReporter {
2121
public:
22-
virtual bool ReportContext(const Context& context) override {
22+
bool ReportContext(const Context& context) override {
2323
return ConsoleReporter::ReportContext(context);
2424
};
2525

26-
virtual void ReportRuns(const std::vector<Run>& report) override {
26+
void ReportRuns(const std::vector<Run>& report) override {
2727
assert(report.size() == 1);
2828
ConsoleReporter::ReportRuns(report);
2929
};
3030

31-
virtual void ReportRunsConfig(double min_time, bool /* has_explicit_iters */,
32-
IterationCount /* iters */) override {
31+
void ReportRunsConfig(double min_time, bool /* has_explicit_iters */,
32+
IterationCount /* iters */) override {
3333
min_times_.push_back(min_time);
3434
}
3535

3636
TestReporter() {}
3737

38-
virtual ~TestReporter() {}
38+
~TestReporter() override {}
3939

4040
const std::vector<double>& GetMinTimes() const { return min_times_; }
4141

test/filter_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int main(int argc, char** argv) {
8585
if (argc == 2) {
8686
// Make sure we ran all of the tests
8787
std::stringstream ss(argv[1]);
88-
int64_t expected_return;
88+
int64_t expected_return = 0;
8989
ss >> expected_return;
9090

9191
if (returned_count != expected_return) {

test/output_test_helper.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ std::string PerformSubstitutions(std::string source) {
8383
SubMap const& subs = GetSubstitutions();
8484
using SizeT = std::string::size_type;
8585
for (auto const& KV : subs) {
86-
SizeT pos;
86+
SizeT pos = 0;
8787
SizeT next_start = 0;
8888
while ((pos = source.find(KV.first, next_start)) != std::string::npos) {
8989
next_start = pos + KV.second.size();

0 commit comments

Comments
 (0)