1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-22 06:50:18 +03:00

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().
This commit is contained in:
Lennart Poettering 2024-11-18 12:32:24 +01:00
parent 6e1b24820f
commit ce2ef96c2b
2 changed files with 7 additions and 0 deletions

View 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;

View 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++)