selftests/nolibc: make result alignment more robust
authorThomas Weißschuh <linux@weissschuh.net>
Wed, 22 Nov 2023 07:27:59 +0000 (08:27 +0100)
committerThomas Weißschuh <linux@weissschuh.net>
Mon, 11 Dec 2023 21:38:31 +0000 (22:38 +0100)
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>
tools/testing/selftests/nolibc/nolibc-test.c

index e173014f6b667ddc735de8895a9fe0347fd22462..2b71fb5fae4e6a90770b4b0a6f7670db4667e8b0 100644 (file)
@@ -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);
 }