Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit e23e477

Browse files
authored
Lint fixes for fml, tools subdirs (#19990)
This does lint fixes for the fml and tools subdirs.
1 parent 7c5162e commit e23e477

19 files changed

+137
-98
lines changed

fml/ascii_trie.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// FLUTTER_NOLINT
4+
55
#include "flutter/fml/ascii_trie.h"
66
#include "flutter/fml/logging.h"
77

@@ -38,7 +38,7 @@ bool AsciiTrie::Query(TrieNode* trie, const char* query) {
3838
FML_DCHECK(trie);
3939
const char* char_position = query;
4040
TrieNode* trie_position = trie;
41-
TrieNode* child;
41+
TrieNode* child = nullptr;
4242
int ch;
4343
while ((ch = *char_position) && (child = trie_position->children[ch].get())) {
4444
char_position++;

fml/command_line.cc

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// FLUTTER_NOLINT
54

65
#include "flutter/fml/command_line.h"
76

@@ -27,8 +26,9 @@ CommandLine::CommandLine(const std::string& argv0,
2726
argv0_(argv0),
2827
options_(options),
2928
positional_args_(positional_args) {
30-
for (size_t i = 0; i < options_.size(); i++)
29+
for (size_t i = 0; i < options_.size(); i++) {
3130
option_index_[options_[i].name] = i;
31+
}
3232
}
3333

3434
CommandLine::~CommandLine() = default;
@@ -39,18 +39,21 @@ CommandLine& CommandLine::operator=(CommandLine&& from) = default;
3939

4040
bool CommandLine::HasOption(std::string_view name, size_t* index) const {
4141
auto it = option_index_.find(name.data());
42-
if (it == option_index_.end())
42+
if (it == option_index_.end()) {
4343
return false;
44-
if (index)
44+
}
45+
if (index) {
4546
*index = it->second;
47+
}
4648
return true;
4749
}
4850

4951
bool CommandLine::GetOptionValue(std::string_view name,
5052
std::string* value) const {
5153
size_t index;
52-
if (!HasOption(name, &index))
54+
if (!HasOption(name, &index)) {
5355
return false;
56+
}
5457
*value = options_[index].value;
5558
return true;
5659
}
@@ -59,8 +62,9 @@ std::vector<std::string_view> CommandLine::GetOptionValues(
5962
std::string_view name) const {
6063
std::vector<std::string_view> ret;
6164
for (const auto& option : options_) {
62-
if (option.name == name)
65+
if (option.name == name) {
6366
ret.push_back(option.value);
67+
}
6468
}
6569
return ret;
6670
}
@@ -69,8 +73,9 @@ std::string CommandLine::GetOptionValueWithDefault(
6973
std::string_view name,
7074
std::string_view default_value) const {
7175
size_t index;
72-
if (!HasOption(name, &index))
76+
if (!HasOption(name, &index)) {
7377
return {default_value.data(), default_value.size()};
78+
}
7479
return options_[index].value;
7580
}
7681

@@ -125,16 +130,18 @@ bool CommandLineBuilder::ProcessArg(const std::string& arg) {
125130
}
126131

127132
CommandLine CommandLineBuilder::Build() const {
128-
if (!has_argv0_)
133+
if (!has_argv0_) {
129134
return CommandLine();
135+
}
130136
return CommandLine(argv0_, options_, positional_args_);
131137
}
132138

133139
} // namespace internal
134140

135141
std::vector<std::string> CommandLineToArgv(const CommandLine& command_line) {
136-
if (!command_line.has_argv0())
142+
if (!command_line.has_argv0()) {
137143
return std::vector<std::string>();
144+
}
138145

139146
std::vector<std::string> argv;
140147
const std::vector<CommandLine::Option>& options = command_line.options();
@@ -146,17 +153,19 @@ std::vector<std::string> CommandLineToArgv(const CommandLine& command_line) {
146153

147154
argv.push_back(command_line.argv0());
148155
for (const auto& option : options) {
149-
if (option.value.empty())
156+
if (option.value.empty()) {
150157
argv.push_back("--" + option.name);
151-
else
158+
} else {
152159
argv.push_back("--" + option.name + "=" + option.value);
160+
}
153161
}
154162

155163
if (!positional_args.empty()) {
156164
// Insert a "--" if necessary.
157165
if (positional_args[0].size() >= 2u && positional_args[0][0] == '-' &&
158-
positional_args[0][1] == '-')
166+
positional_args[0][1] == '-') {
159167
argv.push_back("--");
168+
}
160169

161170
argv.insert(argv.end(), positional_args.begin(), positional_args.end());
162171
}

fml/icu_util.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// FLUTTER_NOLINT
54

65
#include "flutter/fml/icu_util.h"
76

@@ -20,11 +19,12 @@ namespace icu {
2019

2120
class ICUContext {
2221
public:
23-
ICUContext(const std::string& icu_data_path) : valid_(false) {
22+
explicit ICUContext(const std::string& icu_data_path) : valid_(false) {
2423
valid_ = SetupMapping(icu_data_path) && SetupICU();
2524
}
2625

27-
ICUContext(std::unique_ptr<Mapping> mapping) : mapping_(std::move(mapping)) {
26+
explicit ICUContext(std::unique_ptr<Mapping> mapping)
27+
: mapping_(std::move(mapping)) {
2828
valid_ = SetupICU();
2929
}
3030

fml/logging.cc

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// FLUTTER_NOLINT
54

65
#include <algorithm>
76
#include <iostream>
@@ -23,23 +22,26 @@ const char* const kLogSeverityNames[LOG_NUM_SEVERITIES] = {"INFO", "WARNING",
2322
"ERROR", "FATAL"};
2423

2524
const char* GetNameForLogSeverity(LogSeverity severity) {
26-
if (severity >= LOG_INFO && severity < LOG_NUM_SEVERITIES)
25+
if (severity >= LOG_INFO && severity < LOG_NUM_SEVERITIES) {
2726
return kLogSeverityNames[severity];
27+
}
2828
return "UNKNOWN";
2929
}
3030

3131
const char* StripDots(const char* path) {
32-
while (strncmp(path, "../", 3) == 0)
32+
while (strncmp(path, "../", 3) == 0) {
3333
path += 3;
34+
}
3435
return path;
3536
}
3637

3738
const char* StripPath(const char* path) {
3839
auto* p = strrchr(path, '/');
39-
if (p)
40+
if (p) {
4041
return p + 1;
41-
else
42+
} else {
4243
return path;
44+
}
4345
}
4446

4547
} // namespace
@@ -50,15 +52,17 @@ LogMessage::LogMessage(LogSeverity severity,
5052
const char* condition)
5153
: severity_(severity), file_(file), line_(line) {
5254
stream_ << "[";
53-
if (severity >= LOG_INFO)
55+
if (severity >= LOG_INFO) {
5456
stream_ << GetNameForLogSeverity(severity);
55-
else
57+
} else {
5658
stream_ << "VERBOSE" << -severity;
59+
}
5760
stream_ << ":" << (severity > LOG_INFO ? StripDots(file_) : StripPath(file_))
5861
<< "(" << line_ << ")] ";
5962

60-
if (condition)
63+
if (condition) {
6164
stream_ << "Check failed: " << condition << ". ";
65+
}
6266
}
6367

6468
LogMessage::~LogMessage() {

fml/memory/ref_counted_unittest.cc

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2013 The Flutter Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
4-
// FLUTTER_NOLINT
54

65
// This file tests both ref_counted.h and ref_ptr.h (which the former includes).
76
// TODO(vtl): Possibly we could separate these tests out better, since a lot of
@@ -47,12 +46,14 @@ class MyClass : public RefCountedThreadSafe<MyClass> {
4746
protected:
4847
MyClass(MyClass** created, bool* was_destroyed)
4948
: was_destroyed_(was_destroyed) {
50-
if (created)
49+
if (created) {
5150
*created = this;
51+
}
5252
}
5353
virtual ~MyClass() {
54-
if (was_destroyed_)
54+
if (was_destroyed_) {
5555
*was_destroyed_ = true;
56+
}
5657
}
5758

5859
private:
@@ -71,8 +72,9 @@ class MySubclass final : public MyClass {
7172

7273
MySubclass(MySubclass** created, bool* was_destroyed)
7374
: MyClass(nullptr, was_destroyed) {
74-
if (created)
75+
if (created) {
7576
*created = this;
77+
}
7678
}
7779
~MySubclass() override {}
7880

@@ -225,7 +227,7 @@ TEST(RefCountedTest, NullAssignmentToNull) {
225227
// No-op null assignment using move constructor.
226228
r1 = std::move(r2);
227229
EXPECT_TRUE(r1.get() == nullptr);
228-
EXPECT_TRUE(r2.get() == nullptr);
230+
EXPECT_TRUE(r2.get() == nullptr); // NOLINT(clang-analyzer-cplusplus.Move)
229231
EXPECT_FALSE(r1);
230232
EXPECT_FALSE(r2);
231233

@@ -270,7 +272,7 @@ TEST(RefCountedTest, NonNullAssignmentToNull) {
270272
RefPtr<MyClass> r2;
271273
// Move assignment (to null ref pointer).
272274
r2 = std::move(r1);
273-
EXPECT_TRUE(r1.get() == nullptr);
275+
EXPECT_TRUE(r1.get() == nullptr); // NOLINT(clang-analyzer-cplusplus.Move)
274276
EXPECT_EQ(created, r2.get());
275277
EXPECT_FALSE(r1);
276278
EXPECT_TRUE(r2);
@@ -334,7 +336,7 @@ TEST(RefCountedTest, NullAssignmentToNonNull) {
334336
// Null assignment using move constructor.
335337
r1 = std::move(r2);
336338
EXPECT_TRUE(r1.get() == nullptr);
337-
EXPECT_TRUE(r2.get() == nullptr);
339+
EXPECT_TRUE(r2.get() == nullptr); // NOLINT(clang-analyzer-cplusplus.Move)
338340
EXPECT_FALSE(r1);
339341
EXPECT_FALSE(r2);
340342
EXPECT_TRUE(was_destroyed);
@@ -387,7 +389,7 @@ TEST(RefCountedTest, NonNullAssignmentToNonNull) {
387389
RefPtr<MyClass> r2(MakeRefCounted<MyClass>(nullptr, &was_destroyed2));
388390
// Move assignment (to non-null ref pointer).
389391
r2 = std::move(r1);
390-
EXPECT_TRUE(r1.get() == nullptr);
392+
EXPECT_TRUE(r1.get() == nullptr); // NOLINT(clang-analyzer-cplusplus.Move)
391393
EXPECT_FALSE(r2.get() == nullptr);
392394
EXPECT_FALSE(r1);
393395
EXPECT_TRUE(r2);
@@ -596,13 +598,14 @@ TEST(RefCountedTest, PublicCtorAndDtor) {
596598
TEST(RefCountedTest, DebugChecks) {
597599
{
598600
MyPublicClass* p = new MyPublicClass();
599-
EXPECT_DEATH_IF_SUPPORTED(delete p, "!adoption_required_");
601+
EXPECT_DEATH_IF_SUPPORTED( // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks)
602+
delete p, "!adoption_required_");
600603
}
601604

602605
{
603606
MyPublicClass* p = new MyPublicClass();
604-
EXPECT_DEATH_IF_SUPPORTED(RefPtr<MyPublicClass> r(p),
605-
"!adoption_required_");
607+
EXPECT_DEATH_IF_SUPPORTED( // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks)
608+
RefPtr<MyPublicClass> r(p), "!adoption_required_");
606609
}
607610

608611
{

fml/memory/ref_ptr.h

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,42 +66,48 @@ template <typename T>
6666
class RefPtr final {
6767
public:
6868
RefPtr() : ptr_(nullptr) {}
69-
RefPtr(std::nullptr_t) : ptr_(nullptr) {}
69+
RefPtr(std::nullptr_t)
70+
: ptr_(nullptr) {} // NOLINT(google-explicit-constructor)
7071

7172
// Explicit constructor from a plain pointer (to an object that must have
7273
// already been adopted). (Note that in |T::T()|, references to |this| cannot
7374
// be taken, since the object being constructed will not have been adopted
7475
// yet.)
7576
template <typename U>
7677
explicit RefPtr(U* p) : ptr_(p) {
77-
if (ptr_)
78+
if (ptr_) {
7879
ptr_->AddRef();
80+
}
7981
}
8082

8183
// Copy constructor.
8284
RefPtr(const RefPtr<T>& r) : ptr_(r.ptr_) {
83-
if (ptr_)
85+
if (ptr_) {
8486
ptr_->AddRef();
87+
}
8588
}
8689

8790
template <typename U>
88-
RefPtr(const RefPtr<U>& r) : ptr_(r.ptr_) {
89-
if (ptr_)
91+
RefPtr(const RefPtr<U>& r)
92+
: ptr_(r.ptr_) { // NOLINT(google-explicit-constructor)
93+
if (ptr_) {
9094
ptr_->AddRef();
95+
}
9196
}
9297

9398
// Move constructor.
9499
RefPtr(RefPtr<T>&& r) : ptr_(r.ptr_) { r.ptr_ = nullptr; }
95100

96101
template <typename U>
97-
RefPtr(RefPtr<U>&& r) : ptr_(r.ptr_) {
102+
RefPtr(RefPtr<U>&& r) : ptr_(r.ptr_) { // NOLINT(google-explicit-constructor)
98103
r.ptr_ = nullptr;
99104
}
100105

101106
// Destructor.
102107
~RefPtr() {
103-
if (ptr_)
108+
if (ptr_) {
104109
ptr_->Release();
110+
}
105111
}
106112

107113
T* get() const { return ptr_; }
@@ -118,25 +124,34 @@ class RefPtr final {
118124

119125
// Copy assignment.
120126
RefPtr<T>& operator=(const RefPtr<T>& r) {
121-
// Call |AddRef()| first so self-assignments work.
122-
if (r.ptr_)
127+
// Handle self-assignment.
128+
if (r.ptr_ == ptr_) {
129+
return *this;
130+
}
131+
if (r.ptr_) {
123132
r.ptr_->AddRef();
133+
}
124134
T* old_ptr = ptr_;
125135
ptr_ = r.ptr_;
126-
if (old_ptr)
136+
if (old_ptr) {
127137
old_ptr->Release();
138+
}
128139
return *this;
129140
}
130141

131142
template <typename U>
132143
RefPtr<T>& operator=(const RefPtr<U>& r) {
133-
// Call |AddRef()| first so self-assignments work.
134-
if (r.ptr_)
144+
if (reinterpret_cast<T*>(r.ptr_) == ptr_) {
145+
return *this;
146+
}
147+
if (r.ptr_) {
135148
r.ptr_->AddRef();
149+
}
136150
T* old_ptr = ptr_;
137151
ptr_ = r.ptr_;
138-
if (old_ptr)
152+
if (old_ptr) {
139153
old_ptr->Release();
154+
}
140155
return *this;
141156
}
142157

0 commit comments

Comments
 (0)