Skip to content

Commit

Permalink
review: Switch to array positions over pointer mathzz
Browse files Browse the repository at this point in the history
  • Loading branch information
Teufelchen1 committed Apr 24, 2024
1 parent 92b7856 commit bb54c04
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions sys/shell/cmds/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,23 +742,19 @@ static char _get_char(unsigned i)
static void _write_block(int fd, unsigned bs, unsigned i)
{
char block[bs];
char *buf = block;

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

if (size_wanted < 0) {
assert(0);
return;
}

/* Did the output got truncated? */
if ((unsigned) size_wanted >= bs) {
buf += bs;
} else {
buf += size_wanted;
/* Only memset the buffer, if there is space left in the buffer */
if ((unsigned) size_wanted < bs) {
memset(&block[size_wanted], _get_char(i), bs - size_wanted);
}

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

vfs_write(fd, block, bs);
Expand Down

0 comments on commit bb54c04

Please sign in to comment.