From 7d2c4c1271d154d619fa289f612594b00f5f41f4 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 11 Dec 2023 21:04:33 +0100 Subject: [PATCH] src: avoid shadowed string in fs_permission --- src/permission/fs_permission.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/permission/fs_permission.h b/src/permission/fs_permission.h index 1c818567934f7d..4577a73c37d889 100644 --- a/src/permission/fs_permission.h +++ b/src/permission/fs_permission.h @@ -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) { @@ -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); @@ -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() {