1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

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.
This commit is contained in:
Simon Tatham 2021-04-18 12:08:50 +01:00
parent 3346b4b83f
commit 397d75648d

View File

@ -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;
}