From 5606d715128edaf1830c895fd3619f1f1af67d56 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Thu, 18 Apr 2024 18:18:53 +0200 Subject: LibC: Fix bug in sv_clone --- userland/libc/tb/sv.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'userland') diff --git a/userland/libc/tb/sv.c b/userland/libc/tb/sv.c index 500d041..ad0a61c 100644 --- a/userland/libc/tb/sv.c +++ b/userland/libc/tb/sv.c @@ -135,11 +135,14 @@ struct sv sv_clone(struct sv s) { char *sv_copy_to_c(struct sv s, char *out, size_t buffer_length) { int copy_len = min(s.length + 1, buffer_length); + if(0 == copy_len) { + return NULL; + } if (!out) { out = malloc(copy_len); } memcpy(out, s.s, copy_len - 1); - out[copy_len] = '\0'; + out[copy_len - 1] = '\0'; return out; } -- cgit v1.2.3