From 4cddd92c6af4d88e1b3a473d63e751340d608f50 Mon Sep 17 00:00:00 2001 From: aPiecek Date: Wed, 4 Dec 2024 16:01:25 +0100 Subject: [PATCH] cli BUGFIX avoid read on -1 in linenoise --- cli/linenoise/linenoise.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cli/linenoise/linenoise.c b/cli/linenoise/linenoise.c index 24121956..2bb6a13f 100644 --- a/cli/linenoise/linenoise.c +++ b/cli/linenoise/linenoise.c @@ -1114,11 +1114,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;