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 <haroldo.santos@gmail.com>
This commit is contained in:
Haroldo Santos authored and Carlos R. Mafra committed 2026-10-21 12:20:34 +01:00
1 parent 9c2b6865be
commit 558e67f303
1 file changed
+2 -1
+2 -1
View File
@@ -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;
}