Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: avoid silent coercion to signed/unsigned int #50663

Merged
merged 1 commit into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/permission/fs_permission.cc
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading