camgunz / cmp

An implementation of the MessagePack serialization format in C / msgpack.org[C]
http://msgpack.org
MIT License
340 stars 78 forks source link

`decode_befloat` and `decode_bedouble` always return 0 on bigendian processors #55

Closed dcurrie closed 3 years ago

dcurrie commented 3 years ago

Reviewing the code, I noticed this:

static float decode_befloat(const char *b) {
  float f = 0.;
  char *fb = (char *)&f;

  if (!is_bigendian()) {
    fb[0] = b[3];
    fb[1] = b[2];
    fb[2] = b[1];
    fb[3] = b[0];
  }

  return f;
}

If is_bigendian() is true, this function always returns zero.

The same defect is in decode_bedouble.

camgunz commented 3 years ago

Oh yeah that's a big goof. Let me fix this when I get some time; good catch!