From 1207977447daba0297212b3cba9e083c30334434 Mon Sep 17 00:00:00 2001 From: Huang Qi Date: Mon, 13 Feb 2023 20:07:53 +0800 Subject: [PATCH] readline: Check the fd before echo Signed-off-by: Huang Qi --- system/readline/readline_fd.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/system/readline/readline_fd.c b/system/readline/readline_fd.c index e3e6101cc..351b416e4 100644 --- a/system/readline/readline_fd.c +++ b/system/readline/readline_fd.c @@ -117,6 +117,13 @@ static void readline_putc(FAR struct rl_common_s *vtbl, int ch) DEBUGASSERT(priv); + /* If outfd is a invalid fd, return directly. */ + + if (priv->outfd < 0) + { + return; + } + /* Loop until we successfully write a character (or until an unexpected * error occurs). */ @@ -149,6 +156,13 @@ static void readline_write(FAR struct rl_common_s *vtbl, FAR struct readline_s *priv = (FAR struct readline_s *)vtbl; DEBUGASSERT(priv && buffer && buflen > 0); + /* If outfd is a invalid fd, return directly. */ + + if (priv->outfd < 0) + { + return; + } + write(priv->outfd, buffer, buflen); } #endif