Skip to content

Commit

Permalink
src: avoid shadowed string in fs_permission
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Dec 12, 2023
1 parent f801b58 commit 7d2c4c1
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/permission/fs_permission.h
Expand Up @@ -32,12 +32,14 @@ class FSPermission final : public PermissionBase {

Node() : wildcard_child(nullptr), is_leaf(false) {}

Node* CreateChild(const std::string& prefix) {
if (prefix.empty() && !is_leaf) {
Node* CreateChild(const std::string& path_prefix) {
if (path_prefix.empty() && !is_leaf) {
is_leaf = true;
return this;
}
char label = prefix[0];

CHECK(!path_prefix.empty());
char label = path_prefix[0];

Node* child = children[label];
if (child == nullptr) {
Expand All @@ -47,9 +49,9 @@ class FSPermission final : public PermissionBase {

// swap prefix
size_t i = 0;
size_t prefix_len = prefix.length();
size_t prefix_len = path_prefix.length();
for (; i < child->prefix.length(); ++i) {
if (i > prefix_len || prefix[i] != child->prefix[i]) {
if (i > prefix_len || path_prefix[i] != child->prefix[i]) {
std::string parent_prefix = child->prefix.substr(0, i);
std::string child_prefix = child->prefix.substr(i);

Expand All @@ -58,11 +60,11 @@ class FSPermission final : public PermissionBase {
split_child->children[child_prefix[0]] = child;
children[parent_prefix[0]] = split_child;

return split_child->CreateChild(prefix.substr(i));
return split_child->CreateChild(path_prefix.substr(i));
}
}
child->is_leaf = true;
return child->CreateChild(prefix.substr(i));
return child->CreateChild(path_prefix.substr(i));
}

Node* CreateWildcardChild() {
Expand Down

0 comments on commit 7d2c4c1

Please sign in to comment.