From ef5a70386d26bf3c4a9212077fa6338b07a6a570 Mon Sep 17 00:00:00 2001 From: Leo C Date: Tue, 10 Apr 2018 08:26:33 +0200 Subject: [PATCH] move *cmd_array[] from stack to heap --- avr/command.c | 32 +++++++++++++++++--------------- 1 file 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; } -- 2.39.2