pipe-loader: avoid undefined memcpy behavior

If either dest or src is an invalid or null pointer, the behavior is
undefined, even if count is zero.

Cc: mesa-stable
Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22979>
This commit is contained in:
Yiwei Zhang
2023-05-12 00:46:35 -07:00
committed by Marge Bot
parent d5cf6f7d2f
commit 5b31039033
@@ -97,8 +97,12 @@ merge_driconf(const driOptionDescription *driver_driconf, unsigned driver_count,
return NULL;
}
memcpy(merged, gallium_driconf, sizeof(*merged) * gallium_count);
memcpy(&merged[gallium_count], driver_driconf, sizeof(*merged) * driver_count);
if (gallium_count)
memcpy(merged, gallium_driconf, sizeof(*merged) * gallium_count);
if (driver_count) {
memcpy(&merged[gallium_count], driver_driconf,
sizeof(*merged) * driver_count);
}
*merged_count = driver_count + gallium_count;
return merged;