Skip to content

Commit

Permalink
nshlib/cmd_cat: Avoid casting -1 to size_t as count of nsh_write()
Browse files Browse the repository at this point in the history
Signed-off-by: wangjianyu3 <[email protected]>
  • Loading branch information
JianyuWang0623 authored and xiaoxiang781216 committed Oct 17, 2024
1 parent cb24b74 commit c5c18a2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions nshlib/nsh_fscmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c5c18a2

Please sign in to comment.