Skip to content

Commit 4cddd92

Browse files
lePicimichalvasko
authored andcommitted
cli BUGFIX avoid read on -1 in linenoise
1 parent 0fab177 commit 4cddd92

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

cli/linenoise/linenoise.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,11 +1114,14 @@ void linenoiseEditDeletePrevWord(struct linenoiseState *l) {
11141114
* STDIN_FILENO and STDOUT_FILENO.
11151115
*/
11161116
int linenoiseEditStart(struct linenoiseState *l, int stdin_fd, int stdout_fd, char *buf, size_t buflen, const char *prompt) {
1117+
if (stdin_fd == -1) stdin_fd = STDIN_FILENO;
1118+
if (stdout_fd == -1) stdout_fd = STDOUT_FILENO;
1119+
11171120
/* Populate the linenoise state that we pass to functions implementing
11181121
* specific editing functionalities. */
11191122
l->in_completion = 0;
1120-
l->ifd = stdin_fd != -1 ? stdin_fd : STDIN_FILENO;
1121-
l->ofd = stdout_fd != -1 ? stdout_fd : STDOUT_FILENO;
1123+
l->ifd = stdin_fd;
1124+
l->ofd = stdout_fd;
11221125
l->buf = buf;
11231126
l->buflen = buflen;
11241127
l->prompt = prompt;

0 commit comments

Comments
 (0)