From fc43d5c7a02babe6865a51a7f2d4c94b3843db15 Mon Sep 17 00:00:00 2001 From: James Clarke Date: Tue, 7 Jan 2020 19:19:22 +0000 Subject: Fix parsing long options in the C emulator for RVFI-DII idx, passed as longindex to getopt_long, is updated every time a long option is parsed to be the index of that option in the options array, not argv. We should instead use optind as in the non-RVFI-DII case, and we can remove the variable to avoid confusion since it is unused. --- c_emulator/riscv_sim.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'c_emulator/riscv_sim.c') diff --git a/c_emulator/riscv_sim.c b/c_emulator/riscv_sim.c index 2996011..686e3b4 100644 --- a/c_emulator/riscv_sim.c +++ b/c_emulator/riscv_sim.c @@ -193,7 +193,7 @@ static void read_dtb(const char *path) char *process_args(int argc, char **argv) { - int c, idx = 1; + int c; uint64_t ram_size = 0; while(true) { c = getopt_long(argc, argv, @@ -214,7 +214,7 @@ char *process_args(int argc, char **argv) "V::" "v::" "l:" - , options, &idx); + , options, NULL); if (c == -1) break; switch (c) { case 'a': @@ -299,7 +299,7 @@ char *process_args(int argc, char **argv) } if (do_dump_dts) dump_dts(); #ifdef RVFI_DII - if (idx > argc || (idx == argc && !rvfi_dii)) print_usage(argv[0], 0); + if (optind > argc || (optind == argc && !rvfi_dii)) print_usage(argv[0], 0); #else if (optind >= argc) { fprintf(stderr, "No elf file provided.\n"); -- cgit v1.1