mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-03-27 08:46:11 +01:00
strict-aliasing rule
This commit is contained in:
parent
1066bb38a8
commit
d8212ad620
@ -554,19 +554,19 @@ if(sizeof(unsigned long long) == 2) {
|
||||
|
||||
msgpack_pack_inline_func(_float)(msgpack_pack_user x, float d)
|
||||
{
|
||||
union { char buf[4]; uint32_t num; } f;
|
||||
*((float*)&f.buf) = d; // FIXME
|
||||
union { float f; uint32_t i; } mem;
|
||||
mem.f = d;
|
||||
unsigned char buf[5];
|
||||
buf[0] = 0xca; *(uint32_t*)&buf[1] = _msgpack_be32(f.num);
|
||||
buf[0] = 0xca; *(uint32_t*)&buf[1] = _msgpack_be32(mem.i);
|
||||
msgpack_pack_append_buffer(x, buf, 5);
|
||||
}
|
||||
|
||||
msgpack_pack_inline_func(_double)(msgpack_pack_user x, double d)
|
||||
{
|
||||
union { char buf[8]; uint64_t num; } f;
|
||||
*((double*)&f.buf) = d; // FIXME
|
||||
union { double f; uint64_t i; } mem;
|
||||
mem.f = d;
|
||||
unsigned char buf[9];
|
||||
buf[0] = 0xcb; *(uint64_t*)&buf[1] = _msgpack_be64(f.num);
|
||||
buf[0] = 0xcb; *(uint64_t*)&buf[1] = _msgpack_be64(mem.i);
|
||||
msgpack_pack_append_buffer(x, buf, 9);
|
||||
}
|
||||
|
||||
|
@ -222,13 +222,13 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
|
||||
//case CS_
|
||||
//case CS_
|
||||
case CS_FLOAT: {
|
||||
union { uint32_t num; char buf[4]; } f;
|
||||
f.num = PTR_CAST_32(n); // FIXME
|
||||
push_fixed_value(_float, *((float*)f.buf)); }
|
||||
union { uint32_t i; float f; } mem;
|
||||
mem.i = PTR_CAST_32(n);
|
||||
push_fixed_value(_float, mem.f); }
|
||||
case CS_DOUBLE: {
|
||||
union { uint64_t num; char buf[8]; } f;
|
||||
f.num = PTR_CAST_64(n); // FIXME
|
||||
push_fixed_value(_double, *((double*)f.buf)); }
|
||||
union { uint64_t i; double f; } mem;
|
||||
mem.i = PTR_CAST_64(n);
|
||||
push_fixed_value(_double, mem.f); }
|
||||
case CS_UINT_8:
|
||||
push_fixed_value(_uint8, (uint8_t)PTR_CAST_8(n));
|
||||
case CS_UINT_16:
|
||||
|
Loading…
x
Reference in New Issue
Block a user