Skip to content

Commit d0ea738

Browse files
committed
[nrf fromtree] shell: Added assert
Assert to check columns. Averts a potential divide by zero Signed-off-by: Kristoffer Rist Skøien <[email protected]> (cherry picked from commit c73c5d9)
1 parent 69b937d commit d0ea738

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

subsys/shell/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ config SHELL_PRINTF_BUFF_SIZE
9191

9292
config SHELL_DEFAULT_TERMINAL_WIDTH
9393
int "Default terminal width"
94+
range 1 $(UINT16_MAX)
9495
default 80
9596
help
9697
Default terminal width is used to break lines.

subsys/shell/shell.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ static void tab_item_print(const struct shell *sh, const char *option,
141141

142142
columns = (sh->ctx->vt100_ctx.cons.terminal_wid
143143
- z_shell_strlen(tab)) / longest_option;
144+
__ASSERT_NO_MSG(columns != 0);
144145
diff = longest_option - z_shell_strlen(option);
145146

146147
if (sh->ctx->vt100_ctx.printed_cmd++ % columns == 0U) {

subsys/shell/shell_cmds.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@
6969
/* 10 == {esc, [, 2, 5, 0, ;, 2, 5, 0, '\0'} */
7070
#define SHELL_CURSOR_POSITION_BUFFER (10u)
7171

72-
#define SHELL_DEFAULT_TERMINAL_WIDTH 80
73-
#define SHELL_DEFAULT_TERMINAL_HEIGHT 24
74-
7572
/* Function reads cursor position from terminal. */
7673
static int cursor_position_get(const struct shell *sh, uint16_t *x, uint16_t *y)
7774
{
@@ -408,8 +405,8 @@ static int cmd_resize_default(const struct shell *sh,
408405
ARG_UNUSED(argv);
409406

410407
Z_SHELL_VT100_CMD(sh, SHELL_VT100_SETCOL_80);
411-
sh->ctx->vt100_ctx.cons.terminal_wid = SHELL_DEFAULT_TERMINAL_WIDTH;
412-
sh->ctx->vt100_ctx.cons.terminal_hei = SHELL_DEFAULT_TERMINAL_HEIGHT;
408+
sh->ctx->vt100_ctx.cons.terminal_wid = CONFIG_SHELL_DEFAULT_TERMINAL_WIDTH;
409+
sh->ctx->vt100_ctx.cons.terminal_hei = CONFIG_SHELL_DEFAULT_TERMINAL_HEIGHT;
413410

414411
return 0;
415412
}

0 commit comments

Comments
 (0)