util: fix dangling pointer issues with improper std::stringstream usage (#644)

## Description of change
`std::ostringstream.str()` returns a temporary string so it's invalid to
obtain c_str from it and pass it around.

## Testing
wip
This commit is contained in:
bicarus
2026-04-15 23:25:38 -07:00
committed by GitHub
parent b38160d6c2
commit 6ddae70c5a
3 changed files with 25 additions and 26 deletions
+8 -10
View File
@@ -628,13 +628,12 @@ namespace overlay::windows {
ImGui::Text("Wheel: %ld", mouse->pos_wheel);
// keys
std::stringstream keys;
keys << "[";
std::string keys = "[";
for (auto key : mouse->key_states) {
keys << (key ? "1," : "0,");
keys += (key ? "1," : "0,");
}
keys << "]";
ImGui::Text("Keys: %s", keys.str().c_str());
keys += "]";
ImGui::Text("Keys: %s", keys.c_str());
break;
}
@@ -643,15 +642,14 @@ namespace overlay::windows {
ImGui::Text("Type: Keyboard");
// keys
std::stringstream keys;
keys << "[";
std::string keys = "[";
for (size_t i = 0; i < std::size(keyboard->key_states); i++) {
if (keyboard->key_states[i]) {
keys << i << ",";
keys += std::to_string(i) + ",";
}
}
keys << "]";
ImGui::Text("Keys: %s", keys.str().c_str());
keys += "]";
ImGui::Text("Keys: %s", keys.c_str());
break;
}