From 9e4ecc14e95393befa21ac47a4b013a417f8fece Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 22 Jan 2022 15:31:26 +0900 Subject: [PATCH] [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 9347e4f9019c9ad69584a62f14c9fa4cefec293c because test-harness.c was the basis for qwaq's main.c --- tools/qfcc/test/test-harness.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tools/qfcc/test/test-harness.c b/tools/qfcc/test/test-harness.c index c0aa96b10..bf51508b9 100644 --- a/tools/qfcc/test/test-harness.c +++ b/tools/qfcc/test/test-harness.c @@ -276,24 +276,29 @@ main (int argc, char **argv) if (!load_progs (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); - if (argc > 2) + if (argc) { pr_argc = argc; + } pr_argv = PR_Zone_Malloc (&test_pr, (pr_argc + 1) * 4); 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] = 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); P_INT (&test_pr, 0) = pr_argc; P_POINTER (&test_pr, 1) = PR_SetPointer (&test_pr, pr_argv); test_pr.pr_argc = 2; + PR_ExecuteProgram (&test_pr, main_func); PR_PopFrame (&test_pr); if (options.flote)