libfuzz: add a NULL-termination in to_string

It's more useful if we actually want to use the output as, well, a
string..

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
This commit is contained in:
Antoine Poinsot 2021-01-03 21:21:36 +01:00 committed by Christian Decker
parent 45bb1bfa3c
commit 506d524508
2 changed files with 3 additions and 1 deletions

View File

@ -46,6 +46,7 @@ FUZZ_COMMON_OBJS := \
wire/onion_wiregen.o \
wire/peer_wire.o \
wire/peer_wiregen.o \
wire/tlvstream.o \
wire/towire.o \
wire/wire_io.o \
wire/wire_sync.o

View File

@ -34,10 +34,11 @@ const uint8_t **get_chunks(const void *ctx, const uint8_t *data,
char *to_string(const tal_t *ctx, const u8 *data, size_t data_size)
{
char *string = tal_arr(ctx, char, data_size);
char *string = tal_arr(ctx, char, data_size + 1);
for (size_t i = 0; i < data_size; i++)
string[i] = (char) data[i] % (CHAR_MAX + 1);
string[data_size] = '\0';
return string;
}