diff options
author | Luis Machado <luis.machado@linaro.org> | 2020-08-13 10:32:52 -0300 |
---|---|---|
committer | Luis Machado <luis.machado@linaro.org> | 2020-08-13 10:32:52 -0300 |
commit | a5353ae6cf1716c0ff6f7037dc3c336f0d99ecc1 (patch) | |
tree | 855e49a518963e4865728d74a02d433945909918 /sim | |
parent | ece5bc8ac303ccf03dd066ce7e1cba3a12293e40 (diff) | |
download | gdb-a5353ae6cf1716c0ff6f7037dc3c336f0d99ecc1.zip gdb-a5353ae6cf1716c0ff6f7037dc3c336f0d99ecc1.tar.gz gdb-a5353ae6cf1716c0ff6f7037dc3c336f0d99ecc1.tar.bz2 |
[ARM, sim] Fix build failure with -Werror (PR26365)
There is a bit of a situation in the ARM sim with regards to the handling
of argv. sim_open () gets a const char **argv, but ARM's sim_open gets
clever and decides to modify argv in place via sim_target_parse_command_line.
I'm not sure why.
In any case, here's a fix that makes the code modify a copy of argv instead.
sim/arm/ChangeLog:
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.
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; } |