Module: Mesa Branch: main Commit: 5b31039033114bb8e0de25b87119e8d97186bced URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=5b31039033114bb8e0de25b87119e8d97186bced
Author: Yiwei Zhang <[email protected]> Date: Fri May 12 00:46:35 2023 -0700 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 <[email protected]> Reviewed-by: Mike Blumenkrantz <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22979> --- src/gallium/auxiliary/pipe-loader/pipe_loader.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader.c b/src/gallium/auxiliary/pipe-loader/pipe_loader.c index 1c58eaefd04..5b69599ee4f 100644 --- a/src/gallium/auxiliary/pipe-loader/pipe_loader.c +++ b/src/gallium/auxiliary/pipe-loader/pipe_loader.c @@ -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;
