From 95d4f2bbeb522dab7be0cebf9730aad1e32fb99a Mon Sep 17 00:00:00 2001 From: suchmememanyskill Date: Thu, 31 Dec 2020 20:57:15 +0100 Subject: [PATCH] [script] str - str should not modify ptr --- source/script/args.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/source/script/args.c b/source/script/args.c index d9174a4..e4a26f4 100644 --- a/source/script/args.c +++ b/source/script/args.c @@ -286,11 +286,18 @@ Variable_t solveEquation(scriptCtx_t* ctx, lexarToken_t* tokens, u32 len, u8 sho res.free = 0; } ELIFT(Minus) { - if (!strcmp(res.stringType + strlen(res.stringType) - strlen(val.stringType), val.stringType)) { - *(res.stringType + strlen(res.stringType) - strlen(val.stringType)) = 0; + u32 lenRes = strlen(res.stringType); + u32 valRes = strlen(val.stringType); + if (!strcmp(res.stringType + lenRes - valRes, val.stringType)) { + char *temp = malloc(lenRes - valRes + 1); + memcpy(temp, res.stringType, lenRes - valRes); + temp[lenRes - valRes] = 0; + freeVariable(res); + res.free = 1; + res.stringType = temp; } - if (val.free) free(val.stringType); + freeVariable(val); } ELIFT(Division) { int valLen = strlen(val.stringType); @@ -301,7 +308,6 @@ Variable_t solveEquation(scriptCtx_t* ctx, lexarToken_t* tokens, u32 len, u8 sho char* start = res.stringType; char* find = NULL; - //char** arr = malloc(20); // should be dynamic Vector_t arr = newVec(sizeof(char**), 10); char* temp;