summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-11-18 12:32:24 +0100
committerLennart Poettering <lennart@poettering.net>2025-01-17 17:02:07 +0100
commitce2ef96c2b8ad7569a288a1ecc5aaf06bf34bd07 (patch)
tree77686543835f5c48055d6a2377a066e8795c02f0
parentmkosi: update fedora commit reference (diff)
downloadsystemd-ce2ef96c2b8ad7569a288a1ecc5aaf06bf34bd07.tar.xz
systemd-ce2ef96c2b8ad7569a288a1ecc5aaf06bf34bd07.zip
hexdump: if size is SIZE_MAX, use strlen()
Similar how we do this as various places: if SIZE_MAX is specified as size determine the size automatically via strlen().
-rw-r--r--src/basic/hexdecoct.c3
-rw-r--r--src/test/test-hexdecoct.c4
2 files changed, 7 insertions, 0 deletions
diff --git a/src/basic/hexdecoct.c b/src/basic/hexdecoct.c
index 79e4959be7..1d8e60330c 100644
--- a/src/basic/hexdecoct.c
+++ b/src/basic/hexdecoct.c
@@ -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;
diff --git a/src/test/test-hexdecoct.c b/src/test/test-hexdecoct.c
index 5c39fc7cc2..e5121d148e 100644
--- a/src/test/test-hexdecoct.c
+++ b/src/test/test-hexdecoct.c
@@ -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++)