From 4a1d794a643db93408185064e76aee7606999143 Mon Sep 17 00:00:00 2001 From: Goober5000 Date: Sat, 23 Mar 2024 02:04:48 -0400 Subject: [PATCH] fix crash caused by using a moved variable In #5894, in the `add_dynamic_sexp` function in sexp_lookup.cpp, a call to `sexp->getHelpText()` was moved to the bottom of the function. Normally this would be fine, except that this occasion caused the `sexp` variable to be accessed after a `std::move`. The crash can be avoided by moving the last access of the `sexp` variable just a little bit earlier. --- code/parse/sexp/sexp_lookup.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/parse/sexp/sexp_lookup.cpp b/code/parse/sexp/sexp_lookup.cpp index fbead70a8ef..ba51febd1d5 100644 --- a/code/parse/sexp/sexp_lookup.cpp +++ b/code/parse/sexp/sexp_lookup.cpp @@ -238,14 +238,14 @@ int add_dynamic_sexp(std::unique_ptr&& sexp, sexp_oper_type type) new_op.value = free_op_index; new_op.type = type; + sexp_help_struct new_help; + new_help.id = new_op.value; + new_help.help = sexp->getHelpText(); + global.operator_const_mapping.insert(std::make_pair(new_op.value, std::move(sexp))); // Now actually add the operator to the SEXP containers Operators.push_back(new_op); - - sexp_help_struct new_help; - new_help.id = new_op.value; - new_help.help = sexp->getHelpText(); Sexp_help.push_back(new_help); return new_op.value;