From 37d20a84b07f1bb1d0d94c2c7aeb564903411602 Mon Sep 17 00:00:00 2001 From: lingbin Date: Mon, 18 Mar 2024 10:55:45 -0700 Subject: [PATCH] Fix use-after-move in StringIdMap (#9108) Summary: Using a variable after moving it is bug-prone and is not a good practice. Although the move operation on basic types is equivalent to copying, we should still try to avoid this usage. In the original implementation, `entry` was moved in L82((i.e. it should no longer be used after that), but was used again in L83. This PR fixes this problem. Pull Request resolved: https://github.com/facebookincubator/velox/pull/9108 Reviewed By: xiaoxmeng Differential Revision: D55017924 Pulled By: Yuhta fbshipit-source-id: cab5941afd58192a9b21758f100cf53a83712fc4 --- velox/common/caching/StringIdMap.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/velox/common/caching/StringIdMap.cpp b/velox/common/caching/StringIdMap.cpp index 0a7f79df3e89..4ec5d98984c4 100644 --- a/velox/common/caching/StringIdMap.cpp +++ b/velox/common/caching/StringIdMap.cpp @@ -79,8 +79,8 @@ uint64_t StringIdMap::makeId(std::string_view string) { entry.numInUse = 1; pinnedSize_ += entry.string.size(); auto id = entry.id; - auto& entryInTable = idToString_[id] = std::move(entry); - stringToId_[entryInTable.string] = entry.id; + idToString_[id] = std::move(entry); + stringToId_[string] = id; return lastId_; }