From 384748878642a23f13006c714f3e59b95ced624b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Thu, 23 May 2024 15:58:36 +0300 Subject: [PATCH] wrappers: Only escape arguments that need escaping This avoids inflating the total size of the command line too much. If the input command line is near the max size of a command line (32767 characters), it may grow past that limit when adding the arguments injected by the wrapper. If we excessively quote all arguments that don't need to be quoted, we can more easily run into this situation. Thus, by avoiding excessive quoting, we reduce the risk for this issue to happen. This avoids the issue reported at https://github.com/mstorsjo/llvm-mingw/issues/296. --- wrappers/native-wrapper.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/wrappers/native-wrapper.h b/wrappers/native-wrapper.h index 4e2f3f3..1ac87cd 100644 --- a/wrappers/native-wrapper.h +++ b/wrappers/native-wrapper.h @@ -58,7 +58,11 @@ typedef char TCHAR; #endif #ifdef _WIN32 -static inline TCHAR *escape(const TCHAR *str) { +static inline const TCHAR *escape(const TCHAR *str) { + // If we don't need to escape anything, just return the input string + // as is. + if (!_tcschr(str, ' ') && !_tcschr(str, '"')) + return str; TCHAR *out = malloc((_tcslen(str) * 2 + 3) * sizeof(*out)); TCHAR *ptr = out; int i;