Fix: GPU: Shader Preprocess: Undefined behavior in variable_reference_mutation

This is because the `match` can be referenced by the
`report_error` callback. If the string is reallocated,
the callback could read freed memory.
This commit is contained in:
Clément Foucault
2025-05-06 15:02:36 +02:00
parent e8402f2759
commit 9bef8741a9

View File

@@ -946,8 +946,6 @@ class Preprocessor {
const string suffix = match.suffix().str();
out_str += prefix;
/** IMPORTANT: `match` is invalid after the assignment. */
next_str = definition + suffix;
/* Assert definition doesn't contain any side effect. */
if (value.find("++") != string::npos || value.find("--") != string::npos) {
@@ -1017,6 +1015,9 @@ class Preprocessor {
modified = regex_replace(
modified, regex(R"(([^\.])\b)" + name + R"(\b([^(]))"), "$1" + value + "$2");
/** IMPORTANT: `match` is invalid after the assignment. */
next_str = definition + suffix;
/* Replace whole modified scope in output string. */
replace_all(next_str, original, modified);
}