From 1c560ebf0b4800e6595817da76a74524741a635e Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Sun, 10 Aug 2025 23:28:06 +0100 Subject: [PATCH] Add function to fill str buffer with zeros --- src/primitives/strings/str8/str8.c | 9 +++++++++ src/primitives/strings/str8/str8.h | 1 + 2 files changed, 10 insertions(+) diff --git a/src/primitives/strings/str8/str8.c b/src/primitives/strings/str8/str8.c index 4bbdae8..7a507db 100644 --- a/src/primitives/strings/str8/str8.c +++ b/src/primitives/strings/str8/str8.c @@ -28,6 +28,15 @@ RETURN_STR8: return str; } +Str8 *wapp_str8_alloc_and_fill_buf(const Allocator *allocator, u64 capacity) { + Str8 *out = wapp_str8_alloc_buf(allocator, capacity); + if (out) { + memset(out->buf, 0, capacity); + out->size = capacity; + } + return out; +} + Str8 *wapp_str8_alloc_cstr(const Allocator *allocator, const char *str) { wapp_debug_assert(allocator != NULL && str != NULL, "`allocator` and `str` should not be NULL"); diff --git a/src/primitives/strings/str8/str8.h b/src/primitives/strings/str8/str8.h index ea07f82..b74ffc8 100644 --- a/src/primitives/strings/str8/str8.h +++ b/src/primitives/strings/str8/str8.h @@ -74,6 +74,7 @@ typedef const Str8 Str8RO; * Str8 allocated buffers */ Str8 *wapp_str8_alloc_buf(const Allocator *allocator, u64 capacity); +Str8 *wapp_str8_alloc_and_fill_buf(const Allocator *allocator, u64 capacity); Str8 *wapp_str8_alloc_cstr(const Allocator *allocator, const char *str); Str8 *wapp_str8_alloc_str8(const Allocator *allocator, Str8RO *str); Str8 *wapp_str8_alloc_substr(const Allocator *allocator, Str8RO *str, u64 start, u64 end);