changeset 231:8ebf9e9e06e6

type punning fix attempt
author Louis Opter <kalessin@kalessin.fr>
date Sat, 08 Aug 2015 17:33:31 -0700
parents dae19f5f6e44
children 58468b52ea3c
files fix_type_punning.patch series
diffstat 2 files changed, 32 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/fix_type_punning.patch	Sat Aug 08 17:33:31 2015 -0700
@@ -0,0 +1,31 @@
+# HG changeset patch
+# Parent  23cfafefa564ef94d4b60d3e157dd8ff58b2b5c5
+Properly do type punning on float endian conversion functions
+
+This only showed up with optimizations enabled.
+
+diff --git a/lifx/wire_proto.h b/lifx/wire_proto.h
+--- a/lifx/wire_proto.h
++++ b/lifx/wire_proto.h
+@@ -28,15 +28,17 @@
+ static inline floatle_t
+ lgtd_lifx_wire_htolefloat(float f)
+ {
+-    *(uint32_t *)&f = htole32(*(uint32_t *)&f);
+-    return f;
++    union { float f; uint32_t i; } u  = { .f = f };
++    htole32(u.i);
++    return u.f;
+ }
+ 
+ static inline floatle_t
+ lgtd_lifx_wire_lefloattoh(float f)
+ {
+-    *(uint32_t *)&f = le32toh(*(uint32_t *)&f);
+-    return f;
++    union { float f; uint32_t i; } u  = { .f = f };
++    le32toh(u.i);
++    return u.f;
+ }
+ 
+ enum { LGTD_LIFX_PROTOCOL_PORT = 56700 };
--- a/series	Sat Aug 08 17:11:11 2015 -0700
+++ b/series	Sat Aug 08 17:33:31 2015 -0700
@@ -1,3 +1,4 @@
 fix_a_snprintf_return_value_check.patch
 add_toggle.patch
 more_readme_and_doc_updates.patch
+fix_type_punning.patch