From f8af6390ab6f1ddde59d454fd24cf2fa5c138ac0 Mon Sep 17 00:00:00 2001 From: "BADIM-PC\\Vadim" Date: Fri, 22 Dec 2017 11:48:14 +0300 Subject: [PATCH] This code makes assumption that get_script_config(tic)->singleComment is 3 chars long #478 --- src/code.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/code.c b/src/code.c index ddc1929..d553ede 100644 --- a/src/code.c +++ b/src/code.c @@ -1078,13 +1078,8 @@ static void setCodeMode(Code* code, s32 mode) static void commentLine(Code* code) { - static char Comment[] = "-- "; - enum {Size = sizeof Comment-1}; - - tic_mem* tic = code->tic; - - memcpy(Comment, tic->api.get_script_config(tic)->singleComment, - strlen(tic->api.get_script_config(tic)->singleComment)); + const char* comment = code->tic->api.get_script_config(code->tic)->singleComment; + size_t size = strlen(comment); char* line = getLine(code); @@ -1092,26 +1087,26 @@ static void commentLine(Code* code) while((*line == ' ' || *line == '\t') && line < end) line++; - if(memcmp(line, Comment, Size)) + if(memcmp(line, comment, size)) { - if (strlen(code->src) + Size >= sizeof(tic_code)) + if (strlen(code->src) + size >= sizeof(tic_code)) return; - memmove(line + Size, line, strlen(line)+1); - memcpy(line, Comment, Size); + memmove(line + size, line, strlen(line)+1); + memcpy(line, comment, size); if(code->cursor.position > line) - code->cursor.position += Size; + code->cursor.position += size; } else { - memmove(line, line + Size, strlen(line + Size)+1); + memmove(line, line + size, strlen(line + size)+1); - if(code->cursor.position > line + Size) - code->cursor.position -= Size; + if(code->cursor.position > line + size) + code->cursor.position -= size; } - code->cursor.selection = NULL; + code->cursor.selection = NULL; history(code);