From 37b38dadd77079cd7e537f247dcb0a45301e539b Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Mon, 18 Dec 2023 13:41:53 +0000 Subject: Fix more small UBs Signed-off-by: Laurent Bercot --- src/libstddjb/siovec_gather.c | 2 +- src/libstddjb/stralloc_copyb.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libstddjb/siovec_gather.c b/src/libstddjb/siovec_gather.c index a037b0c..4288141 100644 --- a/src/libstddjb/siovec_gather.c +++ b/src/libstddjb/siovec_gather.c @@ -12,7 +12,7 @@ size_t siovec_gather (struct iovec const *v, unsigned int n, char *s, size_t max { size_t len = v[i].iov_len ; if (len > max - w) len = max - w ; - memmove(s + w, v[i].iov_base, len) ; + if (len) memmove(s + w, v[i].iov_base, len) ; w += len ; } return w ; diff --git a/src/libstddjb/stralloc_copyb.c b/src/libstddjb/stralloc_copyb.c index 26c3a4c..f32c3e5 100644 --- a/src/libstddjb/stralloc_copyb.c +++ b/src/libstddjb/stralloc_copyb.c @@ -5,6 +5,7 @@ int stralloc_copyb (stralloc *sa, char const *s, size_t n) { + if (!n) return 1 ; if (!stralloc_ready(sa, n)) return 0 ; memmove(sa->s, s, n) ; sa->len = n ; -- cgit v1.2.3