From 397d75648d663cacfe21f0c070959b2dd2862259 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 18 Apr 2021 12:08:50 +0100 Subject: [PATCH] test_split_into_argv: fix the generation mode. Something weird was happening in the string handling which caused the output to be full of the kind of gibberish you expect to see from unterminated strings. Rather than debug it in detail, I've taken advantage of now having the utils library conveniently available, and simply used a strbuf, which I _know_ works sensibly. --- windows/utils/split_into_argv.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/windows/utils/split_into_argv.c b/windows/utils/split_into_argv.c index 1f89f3b4..d1d51ff4 100644 --- a/windows/utils/split_into_argv.c +++ b/windows/utils/split_into_argv.c @@ -369,27 +369,29 @@ int main(int argc, char **argv) } if (!strcmp(argv[1], "-split") && argc > 2) { - char *str = malloc(20 + strlen(argv[0]) + strlen(argv[2])); - char *p, *q; + strbuf *cmdline = strbuf_new(); + char *p; - q = str + sprintf(str, "%s -splat ", argv[0]); + strbuf_catf(cmdline, "%s -splat ", argv[0]); printf(" {\""); - for (p = argv[2]; *p; p++, q++) { - switch (*p) { - case '/': printf("\\\\"); *q = '\\'; break; - case '\'': printf("\\\""); *q = '"'; break; - case '_': printf(" "); *q = ' '; break; - default: putchar(*p); *q = *p; break; - } + size_t args_start = cmdline->len; + for (p = argv[2]; *p; p++) { + char c = (*p == '/' ? '\\' : + *p == '\'' ? '"' : + *p == '_' ? ' ' : + *p); + put_byte(cmdline, c); } - *p = '\0'; + write_c_string_literal(stdout, ptrlen_from_asciz( + cmdline->s + args_start)); printf("\", {"); fflush(stdout); - system(str); + system(cmdline->s); printf("}},\n"); + strbuf_free(cmdline); return 0; }