From d49ea96203e2e3bda1f3623b5c9bd1760a0fcdf6 Mon Sep 17 00:00:00 2001 From: Tim Angus Date: Fri, 19 Sep 2025 16:14:50 +0100 Subject: [PATCH] Don't add quotes when not needed for LCC process spawning --- code/tools/lcc/etc/lcc.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/code/tools/lcc/etc/lcc.c b/code/tools/lcc/etc/lcc.c index 8dd0f30b..f4a9eea6 100644 --- a/code/tools/lcc/etc/lcc.c +++ b/code/tools/lcc/etc/lcc.c @@ -219,9 +219,19 @@ char *basename(char *name) { #ifdef WIN32 #include +static int argumentNeedsQuoted(const char *arg) { + if (arg && *arg == '"' && arg[strlen(arg) - 1] == '"') { + // Assume that if it's already fully quoted, it doesn't + // need any further quoting or escaping + return 0; + } + + return !*arg || strpbrk(arg, " \t\""); +} + static char *quoteArgument(const char *arg) { // Quote if it has spaces, tabs, or is empty - if(!*arg || strpbrk(arg, " \t\"")) { + if(argumentNeedsQuoted(arg)) { size_t length = strlen(arg); size_t bufferSize = length * 2 + 3; // maximum escapes + quotes + terminator char *buffer = (char *)malloc(bufferSize);