shell: Added assert
Assert to check columns. Averts a potential divide by zero Signed-off-by: Kristoffer Rist Skøien <kristoffer.skoien@nordicsemi.no>
This commit is contained in:
parent
9564a3b431
commit
c73c5d985e
3 changed files with 4 additions and 5 deletions
|
|
@ -91,6 +91,7 @@ config SHELL_PRINTF_BUFF_SIZE
|
||||||
|
|
||||||
config SHELL_DEFAULT_TERMINAL_WIDTH
|
config SHELL_DEFAULT_TERMINAL_WIDTH
|
||||||
int "Default terminal width"
|
int "Default terminal width"
|
||||||
|
range 1 $(UINT16_MAX)
|
||||||
default 80
|
default 80
|
||||||
help
|
help
|
||||||
Default terminal width is used to break lines.
|
Default terminal width is used to break lines.
|
||||||
|
|
|
||||||
|
|
@ -141,6 +141,7 @@ static void tab_item_print(const struct shell *sh, const char *option,
|
||||||
|
|
||||||
columns = (sh->ctx->vt100_ctx.cons.terminal_wid
|
columns = (sh->ctx->vt100_ctx.cons.terminal_wid
|
||||||
- z_shell_strlen(tab)) / longest_option;
|
- z_shell_strlen(tab)) / longest_option;
|
||||||
|
__ASSERT_NO_MSG(columns != 0);
|
||||||
diff = longest_option - z_shell_strlen(option);
|
diff = longest_option - z_shell_strlen(option);
|
||||||
|
|
||||||
if (sh->ctx->vt100_ctx.printed_cmd++ % columns == 0U) {
|
if (sh->ctx->vt100_ctx.printed_cmd++ % columns == 0U) {
|
||||||
|
|
|
||||||
|
|
@ -69,9 +69,6 @@
|
||||||
/* 10 == {esc, [, 2, 5, 0, ;, 2, 5, 0, '\0'} */
|
/* 10 == {esc, [, 2, 5, 0, ;, 2, 5, 0, '\0'} */
|
||||||
#define SHELL_CURSOR_POSITION_BUFFER (10u)
|
#define SHELL_CURSOR_POSITION_BUFFER (10u)
|
||||||
|
|
||||||
#define SHELL_DEFAULT_TERMINAL_WIDTH 80
|
|
||||||
#define SHELL_DEFAULT_TERMINAL_HEIGHT 24
|
|
||||||
|
|
||||||
/* Function reads cursor position from terminal. */
|
/* Function reads cursor position from terminal. */
|
||||||
static int cursor_position_get(const struct shell *sh, uint16_t *x, uint16_t *y)
|
static int cursor_position_get(const struct shell *sh, uint16_t *x, uint16_t *y)
|
||||||
{
|
{
|
||||||
|
|
@ -408,8 +405,8 @@ static int cmd_resize_default(const struct shell *sh,
|
||||||
ARG_UNUSED(argv);
|
ARG_UNUSED(argv);
|
||||||
|
|
||||||
Z_SHELL_VT100_CMD(sh, SHELL_VT100_SETCOL_80);
|
Z_SHELL_VT100_CMD(sh, SHELL_VT100_SETCOL_80);
|
||||||
sh->ctx->vt100_ctx.cons.terminal_wid = SHELL_DEFAULT_TERMINAL_WIDTH;
|
sh->ctx->vt100_ctx.cons.terminal_wid = CONFIG_SHELL_DEFAULT_TERMINAL_WIDTH;
|
||||||
sh->ctx->vt100_ctx.cons.terminal_hei = SHELL_DEFAULT_TERMINAL_HEIGHT;
|
sh->ctx->vt100_ctx.cons.terminal_hei = CONFIG_SHELL_DEFAULT_TERMINAL_HEIGHT;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue