summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo C2018-04-10 08:26:33 +0200
committerLeo C2018-07-21 16:15:55 +0200
commit292f0519ea34caacfd03d3c752fd830056f1b342 (patch)
tree13e395e97aab245f2f660d0da27d3be022e4b3e7
parent7a1ed62033184b79388b541258a14bc579389bdb (diff)
downloadz180-stamp-292f0519ea34caacfd03d3c752fd830056f1b342.zip
move *cmd_array[] from stack to heap
-rw-r--r--avr/command.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/avr/command.c b/avr/command.c
index e88e2f3..c8a73f0 100644
--- a/avr/command.c
+++ b/avr/command.c
@@ -166,39 +166,41 @@ command_ret_t do_help(cmd_tbl_t *cmdtp, uint_fast8_t flag UNUSED, int argc, char
if (argc == 1) { /*show list of commands */
int cmd_items = cmd_tbl_item_count(tbl_start);
- cmd_tbl_t *cmd_array[cmd_items];
- cmd_tbl_t *tp = tbl_start;
- uint_fast8_t max_len = 0;
+ cmd_tbl_t **cmd_list = (cmd_tbl_t **) malloc(cmd_items * sizeof(cmd_tbl_t *));
+ uint_fast8_t maxlen_cmd = 0;
- /* Make array of commands from .uboot_cmd section */
+ /* Make array of commands */
+ cmd_tbl_t *tp = tbl_start;
for (int i = 0; i < cmd_items; i++) {
- cmd_array[i] = tp++;
- uint_fast8_t l = strlen_P(cmd_array[i]->name);
- if (l > max_len)
- max_len = l;
+ uint_fast8_t l = strlen_P(tp->name);
+ if (l > maxlen_cmd)
+ maxlen_cmd = l;
+ cmd_list[i] = tp++;
}
-
/* Sort command list */
- qsort(cmd_array, cmd_items, sizeof (cmd_tbl_t *), cmpstring_PP);
+ qsort(cmd_list, cmd_items, sizeof (cmd_tbl_t *), cmpstring_PP);
/* print short help (usage) */
for (int i = 0; i < cmd_items; i++) {
- if (opt_debug || !(cmd_array[i]->flags & CTBL_DBG)) {
- const FLASH char *usage = cmd_array[i]->usage;
+ if (opt_debug || !(cmd_list[i]->flags & CTBL_DBG)) {
+ const FLASH char *usage = cmd_list[i]->usage;
/* allow user abort */
- if (ctrlc ())
+ if (ctrlc ()) {
+ free(cmd_list);
return CMD_RET_FAILURE;
+ }
if (usage == NULL)
continue;
#if defined(GCC_BUG_61443) || 1
- print_usage_line(cmd_array[i]->name, max_len, usage);
+ print_usage_line(cmd_list[i]->name, maxlen_cmd, usage);
#else
printf_P(PSTR("%-" stringify(8) /*FIXME*/ "S - %S\n"),
- cmd_array[i]->name, usage);
+ cmd_list[i]->name, usage);
#endif
}
}
+ free(cmd_list);
return CMD_RET_SUCCESS;
}