From 631ccc568927a4739a98868ae6970ae3517e9770 Mon Sep 17 00:00:00 2001 From: Michal Vasko Date: Wed, 4 Dec 2024 15:47:23 +0100 Subject: [PATCH] linenoise BUGFIX avoid read on -1 --- tools/lint/linenoise/linenoise.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/lint/linenoise/linenoise.c b/tools/lint/linenoise/linenoise.c index 202295b11..15bdad3c4 100644 --- a/tools/lint/linenoise/linenoise.c +++ b/tools/lint/linenoise/linenoise.c @@ -1106,11 +1106,14 @@ void linenoiseEditDeletePrevWord(struct linenoiseState *l) { * STDIN_FILENO and STDOUT_FILENO. */ int linenoiseEditStart(struct linenoiseState *l, int stdin_fd, int stdout_fd, char *buf, size_t buflen, const char *prompt) { + if (stdin_fd == -1) stdin_fd = STDIN_FILENO; + if (stdout_fd == -1) stdout_fd = STDOUT_FILENO; + /* Populate the linenoise state that we pass to functions implementing * specific editing functionalities. */ l->in_completion = 0; - l->ifd = stdin_fd != -1 ? stdin_fd : STDIN_FILENO; - l->ofd = stdout_fd != -1 ? stdout_fd : STDOUT_FILENO; + l->ifd = stdin_fd; + l->ofd = stdout_fd; l->buf = buf; l->buflen = buflen; l->prompt = prompt;