]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
hexdump: if size is SIZE_MAX, use strlen()
authorLennart Poettering <lennart@poettering.net>
Mon, 18 Nov 2024 11:32:24 +0000 (12:32 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 17 Jan 2025 16:02:07 +0000 (17:02 +0100)
Similar how we do this as various places: if SIZE_MAX is specified as
size determine the size automatically via strlen().

src/basic/hexdecoct.c
src/test/test-hexdecoct.c

index 79e4959be79047b79167c70648668da529d7b1f8..1d8e60330c25645a5b54607d559f42b267259a89 100644 (file)
@@ -866,6 +866,9 @@ void hexdump(FILE *f, const void *p, size_t s) {
 
         assert(b || s == 0);
 
+        if (s == SIZE_MAX)
+                s = strlen(p);
+
         if (!f)
                 f = stdout;
 
index 5c39fc7cc2269c8d423d703e4423087c9603bd59..e5121d148e1893a549fc3565b7910f451c40aae1 100644 (file)
@@ -503,11 +503,15 @@ TEST(hexdump) {
 
         hexdump(stdout, NULL, 0);
         hexdump(stdout, "", 0);
+        hexdump(stdout, "", SIZE_MAX);
         hexdump(stdout, "", 1);
         hexdump(stdout, "x", 1);
+        hexdump(stdout, "x", SIZE_MAX);
         hexdump(stdout, "x", 2);
         hexdump(stdout, "foobar", 7);
+        hexdump(stdout, "foobar", SIZE_MAX);
         hexdump(stdout, "f\nobar", 7);
+        hexdump(stdout, "f\nobar", SIZE_MAX);
         hexdump(stdout, "xxxxxxxxxxxxxxxxxxxxyz", 23);
 
         for (i = 0; i < ELEMENTSOF(data); i++)