This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new c5c18a299 nshlib/cmd_cat: Avoid casting -1 to size_t as count of 
nsh_write()
c5c18a299 is described below

commit c5c18a29973802b196e77adf3fd3e6742a269d83
Author: wangjianyu3 <[email protected]>
AuthorDate: Wed Oct 16 17:52:14 2024 +0800

    nshlib/cmd_cat: Avoid casting -1 to size_t as count of nsh_write()
    
    Signed-off-by: wangjianyu3 <[email protected]>
---
 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 413ed2463..bf23beabe 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);

Reply via email to