From 150a067da5fb92c52dc53906fa0e3feb598c63a4 Mon Sep 17 00:00:00 2001 From: Guillaume Souchere Date: Mon, 13 Jul 2026 08:38:26 +0200 Subject: [PATCH] fix(console): Clamp linenoise cols field to 80 if getColums returns less than that --- components/console/linenoise/linenoise.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/components/console/linenoise/linenoise.c b/components/console/linenoise/linenoise.c index a5847d405fa..547249b0be9 100644 --- a/components/console/linenoise/linenoise.c +++ b/components/console/linenoise/linenoise.c @@ -140,6 +140,7 @@ __thread FILE *linenoise_stdout; #define LINENOISE_MINIMAL_MAX_LINE 64 #define LINENOISE_COMMAND_MAX_LEN 32 #define LINENOISE_PASTE_KEY_DELAY 30 /* Delay, in milliseconds, between two characters being pasted from clipboard */ +#define LINENOISE_DEFAULT_COLS 80 /* Minimum sensible terminal width; used as fallback */ static linenoiseCompletionCallback *completionCallback = NULL; static linenoiseHintsCallback *hintsCallback = NULL; @@ -567,8 +568,8 @@ void refreshShowHints(struct abuf *ab, struct linenoiseState *l, int plen) { * Rewrite the currently edited line accordingly to the buffer content, * cursor position, and number of columns of the terminal. */ static void refreshSingleLine(struct linenoiseState *l) { - if (l->cols == 0) { - l->cols = 80; + if (l->cols < LINENOISE_DEFAULT_COLS) { + l->cols = LINENOISE_DEFAULT_COLS; } char seq[64]; size_t plen = l->plen; @@ -612,8 +613,8 @@ static void refreshSingleLine(struct linenoiseState *l) { * Rewrite the currently edited line accordingly to the buffer content, * cursor position, and number of columns of the terminal. */ static void refreshMultiLine(struct linenoiseState *l) { - if (l->cols == 0) { - l->cols = 80; + if (l->cols < LINENOISE_DEFAULT_COLS) { + l->cols = LINENOISE_DEFAULT_COLS; } char seq[64]; int plen = l->plen; @@ -899,8 +900,8 @@ static int linenoiseEdit(char *buf, size_t buflen, const char *prompt) l.oldpos = l.pos = 0; l.len = 0; l.cols = getColumns(); - if (l.cols == 0) { - l.cols = 80; + if (l.cols < LINENOISE_DEFAULT_COLS) { + l.cols = LINENOISE_DEFAULT_COLS; } l.maxrows = 0; l.history_index = 0;