From ac38f0112d20a4a16bb2787731d23964726b7cd7 Mon Sep 17 00:00:00 2001 From: NaitLee Date: Tue, 11 Jul 2023 09:17:57 +0800 Subject: [PATCH] fix cmd exec a file without ending newline by adding one after read Signed-off-by: NaitLee --- cmd.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd.c b/cmd.c index c9b2cd5d..684be183 100644 --- a/cmd.c +++ b/cmd.c @@ -605,6 +605,7 @@ static void Cmd_StuffCmds_f (cmd_state_t *cmd) static void Cmd_Exec(cmd_state_t *cmd, const char *filename) { char *f; + long int fsize; size_t filenameLen = strlen(filename); qbool isdefaultcfg = !strcmp(filename, "default.cfg") || @@ -617,7 +618,7 @@ static void Cmd_Exec(cmd_state_t *cmd, const char *filename) return; // don't execute config.cfg } - f = (char *)FS_LoadFile (filename, tempmempool, false, NULL); + f = (char *)FS_LoadFile (filename, tempmempool, false, &fsize); if (!f) { Con_Printf("couldn't exec %s\n",filename); @@ -625,6 +626,14 @@ static void Cmd_Exec(cmd_state_t *cmd, const char *filename) } Con_Printf("execing %s\n",filename); + if (f[fsize - 1] != '\n') + { + f = (char *)Mem_Realloc(cbuf_mempool, f, fsize + 2); + f[fsize] = '\n'; + f[fsize + 1] = '\0'; + ++fsize; + } + // if executing default.cfg for the first time, lock the cvar defaults // it may seem backwards to insert this text BEFORE the default.cfg // but Cbuf_InsertText inserts before, so this actually ends up after it. -- 2.39.2