Skip to content

Commit

Permalink
src: avoid shadowed string in fs_permission
Browse files Browse the repository at this point in the history
PR-URL: #51123
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
  • Loading branch information
codebytere authored and richardlau committed Mar 25, 2024
1 parent 1cad0df commit a653531
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/permission/fs_permission.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,26 @@ 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) {
children[label] = new Node(prefix);
children[label] = new Node(path_prefix);
return children[label];
}

// 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 @@ -59,11 +61,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 a653531

Please sign in to comment.