From 3f1322450294f86e4df63826879033aa1b99d8a3 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Fri, 6 Sep 2019 15:36:02 +0100 Subject: [PATCH] d/psmv: Fix strict aliasing warnings when compiling with optimisations --- src/xrt/drivers/psmv/psmv_driver.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/xrt/drivers/psmv/psmv_driver.c b/src/xrt/drivers/psmv/psmv_driver.c index f9bf1e6c7..98fed429d 100644 --- a/src/xrt/drivers/psmv/psmv_driver.c +++ b/src/xrt/drivers/psmv/psmv_driver.c @@ -372,9 +372,14 @@ psmv_vec3_i32_from_i16_wire(struct psmv_vec3_i32 *to, static void psmv_f32_from_wire(float *to, const struct psmv_f32_wire *from) { - uint32_t v = (from->val[0] << 0) | (from->val[1] << 8) | - (from->val[2] << 16) | (from->val[3] << 24); - *to = *((float *)&v); + union { + uint32_t wire; + float f32; + } safe_copy; + + safe_copy.wire = (from->val[0] << 0) | (from->val[1] << 8) | + (from->val[2] << 16) | (from->val[3] << 24); + *to = safe_copy.f32; } static void