From 967a57bdd1a33d1099bceffb82595c9dc6c1c0a4 Mon Sep 17 00:00:00 2001 From: Po-Hsien Wang Date: Fri, 15 Mar 2019 22:53:11 -0700 Subject: [PATCH] vrend_decode_clear: fix undefined-behavior for mis-aligned cast Use memcpy to fix the UBSAN error. Reviewed-by: Elie Tournier Signed-off-by: Dave Airlie --- src/vrend_decode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/vrend_decode.c b/src/vrend_decode.c index 293c9b0..231cd9a 100644 --- a/src/vrend_decode.c +++ b/src/vrend_decode.c @@ -199,7 +199,8 @@ static int vrend_decode_clear(struct vrend_decode_ctx *ctx, int length) buffers = get_buf_entry(ctx, VIRGL_OBJ_CLEAR_BUFFERS); for (i = 0; i < 4; i++) color.ui[i] = get_buf_entry(ctx, VIRGL_OBJ_CLEAR_COLOR_0 + i); - depth = *(double *)(uint64_t *)get_buf_ptr(ctx, VIRGL_OBJ_CLEAR_DEPTH_0); + double *depth_ptr = (double *)(uint64_t *)get_buf_ptr(ctx, VIRGL_OBJ_CLEAR_DEPTH_0); + memcpy(&depth, depth_ptr, sizeof(double)); stencil = get_buf_entry(ctx, VIRGL_OBJ_CLEAR_STENCIL); vrend_clear(ctx->grctx, buffers, &color, depth, stencil);