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 shadowed string in fs_permission #51123

Merged
merged 1 commit into from Jan 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/permission/fs_permission.h
Expand Up @@ -32,24 +32,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];
codebytere marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -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