From 03bcae1918bebdfb7a049390825ba449666be9a0 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Tue, 28 Apr 2015 13:09:38 +0200 Subject: [PATCH] make sure that COMMAND arguments are always in a writeable segment Casting a string constant to "char *" causes segfaults if a command tries to write to it. Now, empty strings are rarely written to, but it is inconsistent, if command arguments change memory segments depending on the argument value. --- source/src/command.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/src/command.cpp b/source/src/command.cpp index 8544bd89..46b78686 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -554,7 +554,7 @@ char *executeret(const char *p) // all evaluation hap } #endif const int MAXWORDS = 25; // limit, remove - char *w[MAXWORDS]; + char *w[MAXWORDS], emptychar = '\0'; char *retval = NULL; #define setretval(v) { char *rv = v; if(rv) retval = rv; } if(noproblem) // if the "seer"-algorithm doesn't object @@ -565,7 +565,7 @@ char *executeret(const char *p) // all evaluation hap int numargs = MAXWORDS, infix = 0; loopi(MAXWORDS) // collect all argument values { - w[i] = (char *)""; + w[i] = &emptychar; if(i>numargs) continue; char *s = parseword(p, i, infix); // parse and evaluate exps if(s) w[i] = s;