Skip to content

Commit c5c18a2

Browse files
JianyuWang0623xiaoxiang781216
authored andcommitted
nshlib/cmd_cat: Avoid casting -1 to size_t as count of nsh_write()
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
1 parent cb24b74 commit c5c18a2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

nshlib/nsh_fscmds.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -801,12 +801,13 @@ int cmd_cat(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
801801

802802
while (true)
803803
{
804-
ssize_t n = nsh_read(vtbl, buf, BUFSIZ);
805-
806-
if (n == 0)
807-
break;
804+
ret = nsh_read(vtbl, buf, BUFSIZ);
805+
if (ret <= 0)
806+
{
807+
break;
808+
}
808809

809-
nsh_write(vtbl, buf, n);
810+
nsh_write(vtbl, buf, ret);
810811
}
811812

812813
free(buf);

0 commit comments

Comments
 (0)