summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Weißschuh <linux@weissschuh.net>2023-11-22 08:27:59 +0100
committerThomas Weißschuh <linux@weissschuh.net>2023-12-11 22:38:31 +0100
commitb9e64724cd8aeca9e7ab4523a92ccf2ba0cd1de2 (patch)
tree56c8763fb8b4dfeee195323b315d1a5c36e861c7
parenttools/nolibc: mips: add support for PIC (diff)
downloadlinux-b9e64724cd8aeca9e7ab4523a92ccf2ba0cd1de2.tar.xz
linux-b9e64724cd8aeca9e7ab4523a92ccf2ba0cd1de2.zip
selftests/nolibc: make result alignment more robust
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 <linux@weissschuh.net>
-rw-r--r--tools/testing/selftests/nolibc/nolibc-test.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index e173014f6b66..2b71fb5fae4e 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -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);
}
@@ -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);
}