Skip to content

Commit fb3db4c

Browse files
mszeszko-metaadamretter
authored andcommitted
[TEMPORARY] cherry-pick of acfea34 (PR facebook#14265) - Work around GCC 12 false positive warning for string::insert (facebook#14265)
Summary: Work around a warning/linter false positive related to the use of string::insert. The code in question is legal C++, but GCC 12's libstdc++ implementation of string::insert internally uses memcpy, which can trigger undefined behavior warnings when the source and destination overlap. Pull Request resolved: facebook#14265 Reviewed By: pdillinger Differential Revision: D91594561 Pulled By: mszeszko-meta fbshipit-source-id: faa1487aba11a6581bf9ac8eb89442b6e4120427
1 parent ff52403 commit fb3db4c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

table/unique_id.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,16 @@ Status GetUniqueIdFromTableProperties(const TableProperties &props,
199199
}
200200

201201
std::string UniqueIdToHumanString(const std::string &id) {
202-
// Not so efficient, but that's OK
203-
std::string str = Slice(id).ToString(/*hex*/ true);
204-
for (size_t i = 16; i < str.size(); i += 17) {
205-
str.insert(i, "-");
202+
std::string hex = Slice(id).ToString(/*hex*/ true);
203+
std::string result;
204+
result.reserve(hex.size() + hex.size() / 16);
205+
for (size_t i = 0; i < hex.size(); i++) {
206+
if (i > 0 && i % 16 == 0) {
207+
result.push_back('-');
208+
}
209+
result.push_back(hex[i]);
206210
}
207-
return str;
211+
return result;
208212
}
209213

210214
std::string InternalUniqueIdToHumanString(UniqueIdPtr in) {

0 commit comments

Comments
 (0)