From c5c18a29973802b196e77adf3fd3e6742a269d83 Mon Sep 17 00:00:00 2001 From: wangjianyu3 Date: Wed, 16 Oct 2024 17:52:14 +0800 Subject: [PATCH] nshlib/cmd_cat: Avoid casting -1 to size_t as count of nsh_write() Signed-off-by: wangjianyu3 --- nshlib/nsh_fscmds.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/nshlib/nsh_fscmds.c b/nshlib/nsh_fscmds.c index 413ed246344..bf23beabe14 100644 --- a/nshlib/nsh_fscmds.c +++ b/nshlib/nsh_fscmds.c @@ -801,12 +801,13 @@ int cmd_cat(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) while (true) { - ssize_t n = nsh_read(vtbl, buf, BUFSIZ); - - if (n == 0) - break; + ret = nsh_read(vtbl, buf, BUFSIZ); + if (ret <= 0) + { + break; + } - nsh_write(vtbl, buf, n); + nsh_write(vtbl, buf, ret); } free(buf);