Skip to content

Commit a1a70db

Browse files
authored
src: avoid silent coercion to signed/unsigned int
Be accurate about signedness and bit widths. PR-URL: #50663 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 9134f4a commit a1a70db

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/permission/fs_permission.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ bool is_tree_granted(node::permission::FSPermission::RadixTree* granted_tree,
5656
// is UNC file path
5757
if (param.rfind("\\\\", 0) == 0) {
5858
// return lookup with normalized param
59-
int starting_pos = 4; // "\\?\"
59+
size_t starting_pos = 4; // "\\?\"
6060
if (param.rfind("\\\\?\\UNC\\") == 0) {
6161
starting_pos += 4; // "UNC\"
6262
}
@@ -176,7 +176,7 @@ bool FSPermission::RadixTree::Lookup(const std::string_view& s,
176176
if (current_node->children.size() == 0) {
177177
return when_empty_return;
178178
}
179-
unsigned int parent_node_prefix_len = current_node->prefix.length();
179+
size_t parent_node_prefix_len = current_node->prefix.length();
180180
const std::string path(s);
181181
auto path_len = path.length();
182182

@@ -202,10 +202,10 @@ bool FSPermission::RadixTree::Lookup(const std::string_view& s,
202202
void FSPermission::RadixTree::Insert(const std::string& path) {
203203
FSPermission::RadixTree::Node* current_node = root_node_;
204204

205-
unsigned int parent_node_prefix_len = current_node->prefix.length();
206-
int path_len = path.length();
205+
size_t parent_node_prefix_len = current_node->prefix.length();
206+
size_t path_len = path.length();
207207

208-
for (int i = 1; i <= path_len; ++i) {
208+
for (size_t i = 1; i <= path_len; ++i) {
209209
bool is_wildcard_node = path[i - 1] == '*';
210210
bool is_last_char = i == path_len;
211211

src/permission/fs_permission.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class FSPermission final : public PermissionBase {
4545
}
4646

4747
// swap prefix
48-
unsigned int i = 0;
49-
unsigned int prefix_len = prefix.length();
48+
size_t i = 0;
49+
size_t prefix_len = prefix.length();
5050
for (; i < child->prefix.length(); ++i) {
5151
if (i > prefix_len || prefix[i] != child->prefix[i]) {
5252
std::string parent_prefix = child->prefix.substr(0, i);
@@ -72,7 +72,7 @@ class FSPermission final : public PermissionBase {
7272
return wildcard_child;
7373
}
7474

75-
Node* NextNode(const std::string& path, unsigned int idx) {
75+
Node* NextNode(const std::string& path, size_t idx) {
7676
if (idx >= path.length()) {
7777
return nullptr;
7878
}
@@ -83,8 +83,8 @@ class FSPermission final : public PermissionBase {
8383
}
8484
auto child = it->second;
8585
// match prefix
86-
unsigned int prefix_len = child->prefix.length();
87-
for (unsigned int i = 0; i < path.length(); ++i) {
86+
size_t prefix_len = child->prefix.length();
87+
for (size_t i = 0; i < path.length(); ++i) {
8888
if (i >= prefix_len || child->prefix[i] == '*') {
8989
return child;
9090
}

0 commit comments

Comments
 (0)