Skip to content

Commit

Permalink
shell/vfs: Handle print failure in genfile cmd gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
Teufelchen1 committed Apr 18, 2024
1 parent 3c3c5c2 commit 17057e6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion sys/shell/cmds/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,19 @@ static void _write_block(int fd, unsigned bs, unsigned i)
char block[bs];
char *buf = block;

buf += snprintf(buf, bs, "|%03u|", i);
int size_wanted = snprintf(buf, bs, "|%03u|", i);

Check failure on line 748 in sys/shell/cmds/vfs.c

View workflow job for this annotation

GitHub Actions / static-tests

trailing whitespace.
if (size_wanted < 0) {
assert(0);
return;
}

/* Did the output got truncated? */
if ((unsigned) size_wanted >= bs) {
buf += bs;
} else {
buf += size_wanted;
}

memset(buf, _get_char(i), &block[bs] - buf);
block[bs - 1] = '\n';
Expand Down

0 comments on commit 17057e6

Please sign in to comment.