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

David Laight posted 8 patches 11 months ago
[PATCH next 5/8] test_hexdump: Fix sample output if zero bytes requested
Posted by David Laight 11 months ago
If 'len' is zero the expected output is an empty string even if
'ascii' is requested.

Signed-off-by: David Laight <david.laight.linux@gmail.com>
---
 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
Re: [PATCH next 5/8] test_hexdump: Fix sample output if zero bytes requested
Posted by Andy Shevchenko 11 months ago
On Sat, Mar 08, 2025 at 09:34:49AM +0000, David Laight wrote:
> If 'len' is zero the expected output is an empty string even if
> 'ascii' is requested.

It's related to the previous one...
So, seems to me the series need a bit more (re-)thinking...

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH next 5/8] test_hexdump: Fix sample output if zero bytes requested
Posted by David Laight 11 months ago
On Mon, 10 Mar 2025 11:03:07 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> On Sat, Mar 08, 2025 at 09:34:49AM +0000, David Laight wrote:
> > If 'len' is zero the expected output is an empty string even if
> > 'ascii' is requested.  
> 
> It's related to the previous one...
> So, seems to me the series need a bit more (re-)thinking...
> 

Nope, all its own bug.
This is a request to hexdump zero bytes into a valid buffer size.
hex_dump_to_buffer() gets it right unless the output buffer length
is also zero.

Found when I started doing a full range of tests.

	David