mirror of
https://github.com/gryf/wmaker.git
synced 2026-11-21 06:27:03 +01:00
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:
1 parent
9c2b6865be
commit
558e67f303
1 file changed
+2
-1
+2
-1
@@ -71,7 +71,8 @@ WMData *WMCreateDataWithBytes(const void *bytes, unsigned length)
|
|||||||
|
|
||||||
aData = WMCreateDataWithCapacity(length);
|
aData = WMCreateDataWithCapacity(length);
|
||||||
aData->length = length;
|
aData->length = length;
|
||||||
memcpy(aData->bytes, bytes, length);
|
if (length > 0)
|
||||||
|
memcpy(aData->bytes, bytes, length);
|
||||||
|
|
||||||
return aData;
|
return aData;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user