Skip to content

Commit 988b3ea

Browse files
committed
src: avoid shadowed string in fs_permission
1 parent f801b58 commit 988b3ea

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/permission/fs_permission.h

+10-8
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,26 @@ class FSPermission final : public PermissionBase {
3232

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

35-
Node* CreateChild(const std::string& prefix) {
36-
if (prefix.empty() && !is_leaf) {
35+
Node* CreateChild(const std::string& path_prefix) {
36+
if (path_prefix.empty() && !is_leaf) {
3737
is_leaf = true;
3838
return this;
3939
}
40-
char label = prefix[0];
40+
41+
CHECK(!path_prefix.empty());
42+
char label = path_prefix[0];
4143

4244
Node* child = children[label];
4345
if (child == nullptr) {
44-
children[label] = new Node(prefix);
46+
children[label] = new Node(path_prefix);
4547
return children[label];
4648
}
4749

4850
// swap prefix
4951
size_t i = 0;
50-
size_t prefix_len = prefix.length();
52+
size_t prefix_len = path_prefix.length();
5153
for (; i < child->prefix.length(); ++i) {
52-
if (i > prefix_len || prefix[i] != child->prefix[i]) {
54+
if (i > prefix_len || path_prefix[i] != child->prefix[i]) {
5355
std::string parent_prefix = child->prefix.substr(0, i);
5456
std::string child_prefix = child->prefix.substr(i);
5557

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

61-
return split_child->CreateChild(prefix.substr(i));
63+
return split_child->CreateChild(path_prefix.substr(i));
6264
}
6365
}
6466
child->is_leaf = true;
65-
return child->CreateChild(prefix.substr(i));
67+
return child->CreateChild(path_prefix.substr(i));
6668
}
6769

6870
Node* CreateWildcardChild() {

0 commit comments

Comments
 (0)