From e34542a3de6b1dbd34339802afdff5a3c0cba0b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Battrel?= Date: Wed, 21 Aug 2024 15:11:35 +0200 Subject: [PATCH] Shell: Make `full_line_cmd` return false on empty lines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The fact that the function was returning `true` for empty line was an unexpected behavior according to the name of the function itself and how it was used elsewhere. Signed-off-by: Théo Battrel --- subsys/shell/shell_ops.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/subsys/shell/shell_ops.c b/subsys/shell/shell_ops.c index 7b9af71e417..b7f68e22a58 100644 --- a/subsys/shell/shell_ops.c +++ b/subsys/shell/shell_ops.c @@ -43,8 +43,13 @@ void z_shell_op_cursor_horiz_move(const struct shell *sh, int32_t delta) */ static inline bool full_line_cmd(const struct shell *sh) { - return ((sh->ctx->cmd_buff_len + z_shell_strlen(sh->ctx->prompt)) - % sh->ctx->vt100_ctx.cons.terminal_wid == 0U); + size_t line_length = sh->ctx->cmd_buff_len + z_shell_strlen(sh->ctx->prompt); + + if (line_length == 0) { + return false; + } + + return (line_length % sh->ctx->vt100_ctx.cons.terminal_wid == 0U); } /* Function returns true if cursor is at beginning of an empty line. */