Skip to content

Commit 2b9441e

Browse files
committed
Correctly terminate Sexp_variable text with a null byte
I'm pretty sure that this is a bug since the documentation of std::string::copy says that it doesn't append a 0 byte so our code would need to do it manually. Instead, the code appended the 0 byte to the input buffer which also conflicts with const-correctness (the function was used on a lua-string buffer which should be const outside Lua).
1 parent 9b1b3e0 commit 2b9441e

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

code/parse/sexp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28877,7 +28877,7 @@ void sexp_add_array_block_variable(int index, bool is_numeric)
2887728877
*
2887828878
* This should be called in mission when an sexp_variable is to be modified
2887928879
*/
28880-
void sexp_modify_variable(char *text, int index, bool sexp_callback)
28880+
void sexp_modify_variable(const char *text, int index, bool sexp_callback)
2888128881
{
2888228882
Assert(index >= 0 && index < MAX_SEXP_VARIABLES);
2888328883
Assert(Sexp_variables[index].type & SEXP_VARIABLE_SET);
@@ -28891,7 +28891,7 @@ void sexp_modify_variable(char *text, int index, bool sexp_callback)
2889128891

2889228892
// copy to original buffer
2889328893
auto len = temp_text.copy(Sexp_variables[index].text, TOKEN_LENGTH);
28894-
text[len] = 0;
28894+
Sexp_variables[index].text[len] = 0;
2889528895
}
2889628896
else
2889728897
{

code/parse/sexp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ int query_node_in_sexp(int node, int sexp);
11761176
void flush_sexp_tree(int node);
11771177

11781178
// sexp_variable
1179-
void sexp_modify_variable(char *text, int index, bool sexp_callback = true);
1179+
void sexp_modify_variable(const char *text, int index, bool sexp_callback = true);
11801180
int get_index_sexp_variable_from_node (int node);
11811181
int get_index_sexp_variable_name(const char *text);
11821182
int get_index_sexp_variable_name(SCP_string &text); // Goober5000

0 commit comments

Comments
 (0)