Skip to content

Commit

Permalink
src: avoid silent coercion to signed/unsigned int
Browse files Browse the repository at this point in the history
Be accurate about signedness and bit widths.

PR-URL: #50663
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
tniessen authored and UlisesGascon committed Dec 11, 2023
1 parent c253e39 commit 3d43fd3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/permission/fs_permission.cc
Expand Up @@ -56,7 +56,7 @@ bool is_tree_granted(node::permission::FSPermission::RadixTree* granted_tree,
// is UNC file path
if (param.rfind("\\\\", 0) == 0) {
// return lookup with normalized param
int starting_pos = 4; // "\\?\"
size_t starting_pos = 4; // "\\?\"
if (param.rfind("\\\\?\\UNC\\") == 0) {
starting_pos += 4; // "UNC\"
}
Expand Down Expand Up @@ -176,7 +176,7 @@ bool FSPermission::RadixTree::Lookup(const std::string_view& s,
if (current_node->children.size() == 0) {
return when_empty_return;
}
unsigned int parent_node_prefix_len = current_node->prefix.length();
size_t parent_node_prefix_len = current_node->prefix.length();
const std::string path(s);
auto path_len = path.length();

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

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

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

Expand Down
10 changes: 5 additions & 5 deletions src/permission/fs_permission.h
Expand Up @@ -45,8 +45,8 @@ class FSPermission final : public PermissionBase {
}

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

Node* NextNode(const std::string& path, unsigned int idx) {
Node* NextNode(const std::string& path, size_t idx) {
if (idx >= path.length()) {
return nullptr;
}
Expand All @@ -83,8 +83,8 @@ class FSPermission final : public PermissionBase {
}
auto child = it->second;
// match prefix
unsigned int prefix_len = child->prefix.length();
for (unsigned int i = 0; i < path.length(); ++i) {
size_t prefix_len = child->prefix.length();
for (size_t i = 0; i < path.length(); ++i) {
if (i >= prefix_len || child->prefix[i] == '*') {
return child;
}
Expand Down

0 comments on commit 3d43fd3

Please sign in to comment.