Skip to content

Commit

Permalink
stek_share: resize instead of reserve (#10793)
Browse files Browse the repository at this point in the history
stek_share indexes into an offset on a string that it reserved space
for, but indexing past size() is undefined behavior. This would result
in crashing on some systems. reszing adjusts the length which satisfies
the indexing requirement.
  • Loading branch information
bneradt authored Nov 15, 2023
1 parent be86589 commit 8d54828
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/experimental/stek_share/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ std::string
hex_str(std::string const &str)
{
std::string hex_str;
hex_str.reserve(str.size() * 2);
hex_str.resize(str.size() * 2);
for (unsigned long int i = 0; i < str.size(); ++i) {
unsigned char c = str.at(i);
hex_str[i * 2] = hex_chars[(c & 0xF0) >> 4];
Expand Down

0 comments on commit 8d54828

Please sign in to comment.