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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user