[PATCH next 5/8] test_hexdump: Fix sample output if zero bytes requested

From: David Laight
Date: Sat Mar 08 2025 - 04:35:55 EST


If 'len' is zero the expected output is an empty string even if
'ascii' is requested.

Signed-off-by: David Laight <david.laight.linux@xxxxxxxxx>
---
lib/test_hexdump.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c
index ed6f0b0a1bb3..07a8cc7e9088 100644
--- a/lib/test_hexdump.c
+++ b/lib/test_hexdump.c
@@ -29,6 +29,11 @@ static size_t __init test_hexdump_prepare_test(size_t len, size_t rowsize,
char *p;
size_t byteswap, i, j;

+ if (!len) {
+ test[0] = 0;
+ return 0;
+ }
+
if (rowsize != 16 && rowsize != 32)
rowsize = 16;

@@ -58,8 +63,7 @@ static size_t __init test_hexdump_prepare_test(size_t len, size_t rowsize,
*p++ = ' ';
}
}
- if (i)
- p--;
+ p--;

/* ASCII part */
if (ascii) {
--
2.39.5