From 2357dee0fead5e436089a8d5d69edb30780397e8 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Wed, 15 Mar 2023 07:58:05 +0000 Subject: [PATCH] Fix allocations at the start of split_into_argv. While doing that parametrisation I noticed three strlen calls that could obviously be replaced with one - and then I also noticed that there were missing parens in an expression that should have been (n+1)/2, making it n + 1/2, i.e. just n, due to integer arithmetic. Happily that bug meant we were _over_-allocating rather than under, but even so, how embarrassing. Fixed. --- windows/utils/split_into_argv.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/windows/utils/split_into_argv.c b/windows/utils/split_into_argv.c index 12fd5ac7..11de889b 100644 --- a/windows/utils/split_into_argv.c +++ b/windows/utils/split_into_argv.c @@ -200,9 +200,12 @@ void FUNCTION(CHAR *cmdline, bool includes_program_name, * This will guaranteeably be big enough; we can realloc it * down later. */ - outputline = snewn(1+STRLEN(cmdline), CHAR); - outputargv = snewn(STRLEN(cmdline)+1 / 2, CHAR *); - outputargstart = snewn(STRLEN(cmdline)+1 / 2, CHAR *); + { + size_t len = STRLEN(cmdline); + outputline = snewn(1+len, CHAR); + outputargv = snewn((len+1) / 2, CHAR *); + outputargstart = snewn((len+1) / 2, CHAR *); + } p = cmdline; q = outputline; outputargc = 0;