Skip to content

Commit

Permalink
Properly do type punning on float endian conversion functions
Browse files Browse the repository at this point in the history
This only showed up with optimizations enabled.
  • Loading branch information
lopter committed Aug 9, 2015
1 parent 4e73596 commit ade73dc
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lifx/wire_proto.h
Expand Up @@ -28,15 +28,17 @@ typedef float floatle_t;
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 };
Expand Down

0 comments on commit ade73dc

Please sign in to comment.