diff options
Diffstat (limited to 'sim')
-rw-r--r-- | sim/arm/ChangeLog | 8 | ||||
-rw-r--r-- | sim/arm/wrapper.c | 42 |
2 files changed, 38 insertions, 12 deletions
diff --git a/sim/arm/ChangeLog b/sim/arm/ChangeLog index d5f9667..1c8f89a 100644 --- a/sim/arm/ChangeLog +++ b/sim/arm/ChangeLog @@ -1,3 +1,11 @@ +2020-08-13 Luis Machado <luis.machado@linaro.org> + + PR sim/26365 + + * wrapper.c (sim_target_parse_command_line): Free discarded argv + entries. + (sim_open): Use a duplicate of argv instead of the original argv. + 2020-01-17 Christian Biesinger <cbiesinger@google.com> * iwmmxt.c: Fix spelling error (seperate). diff --git a/sim/arm/wrapper.c b/sim/arm/wrapper.c index a5ef415..68f8242 100644 --- a/sim/arm/wrapper.c +++ b/sim/arm/wrapper.c @@ -672,7 +672,10 @@ sim_target_parse_command_line (int argc, char ** argv) { /* Remove this option from the argv array. */ for (arg = i; arg < argc; arg ++) - argv[arg] = argv[arg + 1]; + { + free (argv[arg]); + argv[arg] = argv[arg + 1]; + } argc --; i --; trace_funcs = 1; @@ -683,7 +686,10 @@ sim_target_parse_command_line (int argc, char ** argv) { /* Remove this option from the argv array. */ for (arg = i; arg < argc; arg ++) - argv[arg] = argv[arg + 1]; + { + free (argv[arg]); + argv[arg] = argv[arg + 1]; + } argc --; i --; disas = 1; @@ -697,7 +703,10 @@ sim_target_parse_command_line (int argc, char ** argv) { /* Remove this option from the argv array. */ for (arg = i; arg < argc; arg ++) - argv[arg] = argv[arg + 1]; + { + free (argv[arg]); + argv[arg] = argv[arg + 1]; + } argc --; ptr = argv[i]; @@ -733,7 +742,10 @@ sim_target_parse_command_line (int argc, char ** argv) /* Remove this option from the argv array. */ for (arg = i; arg < argc; arg ++) - argv[arg] = argv[arg + 1]; + { + free (argv[arg]); + argv[arg] = argv[arg + 1]; + } argc --; i --; } @@ -774,6 +786,7 @@ sim_open (SIM_OPEN_KIND kind, char * const *argv) { int i; + char **argv_copy; SIM_DESC sd = sim_state_alloc (kind, cb); SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER); @@ -836,21 +849,24 @@ sim_open (SIM_OPEN_KIND kind, sim_callback = cb; - sim_target_parse_arg_array (argv); + /* Copy over the argv contents so we can modify them. */ + argv_copy = dupargv (argv); - if (argv[1] != NULL) + sim_target_parse_arg_array (argv_copy); + + if (argv_copy[1] != NULL) { int i; /* Scan for memory-size switches. */ - for (i = 0; (argv[i] != NULL) && (argv[i][0] != 0); i++) - if (argv[i][0] == '-' && argv[i][1] == 'm') + for (i = 0; (argv_copy[i] != NULL) && (argv_copy[i][0] != 0); i++) + if (argv_copy[i][0] == '-' && argv_copy[i][1] == 'm') { - if (argv[i][2] != '\0') - mem_size = atoi (&argv[i][2]); - else if (argv[i + 1] != NULL) + if (argv_copy[i][2] != '\0') + mem_size = atoi (&argv_copy[i][2]); + else if (argv_copy[i + 1] != NULL) { - mem_size = atoi (argv[i + 1]); + mem_size = atoi (argv_copy[i + 1]); i++; } else @@ -862,6 +878,8 @@ sim_open (SIM_OPEN_KIND kind, } } + freeargv (argv_copy); + return sd; } |