Skip to content

Commit

Permalink
selftests/nolibc: make result alignment more robust
Browse files Browse the repository at this point in the history
Move the check of the existing length into the function so it can't be
forgotten by the caller.

Also hardcode the padding character as only spaces are ever used.

Signed-off-by: Thomas Weißschuh <[email protected]>
  • Loading branch information
t-8ch committed Dec 11, 2023
1 parent 5441024 commit b9e6472
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions tools/testing/selftests/nolibc/nolibc-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,17 @@ static const char *errorname(int err)
}
}

static void putcharn(char c, size_t n)
static void align_result(size_t llen)
{
char buf[64];
const size_t align = 64;
char buf[align];
size_t n;

memset(buf, c, n);
if (llen >= align)
return;

n = align - llen;
memset(buf, ' ', n);
buf[n] = '\0';
fputs(buf, stdout);
}
Expand All @@ -156,8 +162,7 @@ static void result(int llen, enum RESULT r)
else
msg = " [FAIL]";

if (llen < 64)
putcharn(' ', 64 - llen);
align_result(llen);
puts(msg);
}

Expand Down

0 comments on commit b9e6472

Please sign in to comment.