[qfcc] Fix error in handling argc in test-harness

There was an out-by-one where attempting to run a program with only one
argument would result in the argument not being passed to the program
(two worked). This is actually the source of the error fixed in
9347e4f901 because test-harness.c was the
basis for qwaq's main.c
This commit is contained in:
Bill Currie 2022-01-22 15:31:26 +09:00
parent 68d87de251
commit 9e4ecc14e9

View file

@ -276,24 +276,29 @@ main (int argc, char **argv)
if (!load_progs (name)) if (!load_progs (name))
Sys_Error ("couldn't load %s", name); Sys_Error ("couldn't load %s", name);
if ((dfunc = PR_FindFunction (&test_pr, ".main"))
|| (dfunc = PR_FindFunction (&test_pr, "main"))) {
main_func = dfunc - test_pr.pr_functions;
} else {
PR_Undefined (&test_pr, "function", "main");
}
PR_PushFrame (&test_pr); PR_PushFrame (&test_pr);
if (argc > 2) if (argc) {
pr_argc = argc; pr_argc = argc;
}
pr_argv = PR_Zone_Malloc (&test_pr, (pr_argc + 1) * 4); pr_argv = PR_Zone_Malloc (&test_pr, (pr_argc + 1) * 4);
pr_argv[0] = PR_SetTempString (&test_pr, name); pr_argv[0] = PR_SetTempString (&test_pr, name);
for (i = 1; i < pr_argc; i++) for (i = 1; i < pr_argc; i++) {
pr_argv[i] = PR_SetTempString (&test_pr, argv[i]); pr_argv[i] = PR_SetTempString (&test_pr, argv[i]);
}
pr_argv[i] = 0; pr_argv[i] = 0;
if ((dfunc = PR_FindFunction (&test_pr, ".main"))
|| (dfunc = PR_FindFunction (&test_pr, "main")))
main_func = dfunc - test_pr.pr_functions;
else
PR_Undefined (&test_pr, "function", "main");
PR_RESET_PARAMS (&test_pr); PR_RESET_PARAMS (&test_pr);
P_INT (&test_pr, 0) = pr_argc; P_INT (&test_pr, 0) = pr_argc;
P_POINTER (&test_pr, 1) = PR_SetPointer (&test_pr, pr_argv); P_POINTER (&test_pr, 1) = PR_SetPointer (&test_pr, pr_argv);
test_pr.pr_argc = 2; test_pr.pr_argc = 2;
PR_ExecuteProgram (&test_pr, main_func); PR_ExecuteProgram (&test_pr, main_func);
PR_PopFrame (&test_pr); PR_PopFrame (&test_pr);
if (options.flote) if (options.flote)