From 558e67f30331eb03955d7bf3bf4a55c8520c64b6 Mon Sep 17 00:00:00 2001 From: Haroldo Santos Date: Sat, 10 Oct 2026 18:10:13 -0400 Subject: [PATCH] WINGs: do not call memcpy() for empty data in WMCreateDataWithBytes() WMCreateDataWithBytes() always copies 'length' bytes from 'bytes', even when the length is zero. A caller creating an empty WMData naturally passes a NULL pointer in that case, but passing NULL to memcpy() is undefined behavior in C, even with a zero size, and static analyzers report it. Only copy when there is something to copy. The result is unchanged: the data is created with the requested capacity and a length of zero. Signed-off-by: Haroldo Santos --- WINGs/data.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WINGs/data.c b/WINGs/data.c index eb9227bf..510e56e7 100644 --- a/WINGs/data.c +++ b/WINGs/data.c @@ -71,7 +71,8 @@ WMData *WMCreateDataWithBytes(const void *bytes, unsigned length) aData = WMCreateDataWithCapacity(length); aData->length = length; - memcpy(aData->bytes, bytes, length); + if (length > 0) + memcpy(aData->bytes, bytes, length); return aData; }