diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-02-14 13:34:42 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-02-14 13:34:42 +0000 |
commit | d212dc2bf89ec79a85fed3e368d171edd77aa7be (patch) | |
tree | de2ba2d1f0580fdf9313b7a00796357286e2a97f /contrib/libucl/ucl_msgpack.c | |
parent | b7420cb4cb0a2c9c96abc18ecd4de3c2bfec98d3 (diff) | |
download | rspamd-d212dc2bf89ec79a85fed3e368d171edd77aa7be.tar.gz rspamd-d212dc2bf89ec79a85fed3e368d171edd77aa7be.zip |
Backport fixes from libucl
Diffstat (limited to 'contrib/libucl/ucl_msgpack.c')
-rw-r--r-- | contrib/libucl/ucl_msgpack.c | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/contrib/libucl/ucl_msgpack.c b/contrib/libucl/ucl_msgpack.c index 5620a7b11..96f4809f8 100644 --- a/contrib/libucl/ucl_msgpack.c +++ b/contrib/libucl/ucl_msgpack.c @@ -113,19 +113,19 @@ ucl_emitter_print_int_msgpack (struct ucl_emitter_context *ctx, int64_t val) len = 1; buf[0] = mask_positive & val; } - else if (val <= 0xff) { + else if (val <= UINT8_MAX) { len = 2; buf[0] = uint8_ch; buf[1] = val & 0xff; } - else if (val <= 0xffff) { + else if (val <= UINT16_MAX) { uint16_t v = TO_BE16 (val); len = 3; buf[0] = uint16_ch; memcpy (&buf[1], &v, sizeof (v)); } - else if (val <= 0xffffffff) { + else if (val <= UINT32_MAX) { uint32_t v = TO_BE32 (val); len = 5; @@ -149,19 +149,20 @@ ucl_emitter_print_int_msgpack (struct ucl_emitter_context *ctx, int64_t val) len = 1; buf[0] = (mask_negative | uval) & 0xff; } - else if (uval <= 0xff) { + else if (uval <= INT8_MAX) { + uint8_t v = (uint8_t)val; len = 2; buf[0] = int8_ch; - buf[1] = (unsigned char)val; + buf[1] = v; } - else if (uval <= 0xffff) { + else if (uval <= INT16_MAX) { uint16_t v = TO_BE16 (val); len = 3; buf[0] = int16_ch; memcpy (&buf[1], &v, sizeof (v)); } - else if (uval <= 0xffffffff) { + else if (uval <= INT32_MAX) { uint32_t v = TO_BE32 (val); len = 5; @@ -1418,6 +1419,10 @@ ucl_msgpack_parse_int (struct ucl_parser *parser, const unsigned char *pos, size_t remain) { ucl_object_t *obj; + int8_t iv8; + int16_t iv16; + int32_t iv32; + int64_t iv64; if (len > remain) { return -1; @@ -1439,11 +1444,14 @@ ucl_msgpack_parse_int (struct ucl_parser *parser, len = 1; break; case msgpack_int8: - obj->value.iv = (signed char)*pos; + memcpy (&iv8, pos, sizeof (iv8)); + obj->value.iv = iv8; len = 1; break; case msgpack_int16: - obj->value.iv = FROM_BE16 (*(int16_t *)pos); + memcpy (&iv16, pos, sizeof (iv16)); + iv16 = FROM_BE16 (iv16); + obj->value.iv = iv16; len = 2; break; case msgpack_uint16: @@ -1451,7 +1459,9 @@ ucl_msgpack_parse_int (struct ucl_parser *parser, len = 2; break; case msgpack_int32: - obj->value.iv = FROM_BE32 (*(int32_t *)pos); + memcpy (&iv32, pos, sizeof (iv32)); + iv32 = FROM_BE32 (iv32); + obj->value.iv = iv32; len = 4; break; case msgpack_uint32: @@ -1459,7 +1469,9 @@ ucl_msgpack_parse_int (struct ucl_parser *parser, len = 4; break; case msgpack_int64: - obj->value.iv = FROM_BE64 (*(int64_t *)pos); + memcpy (&iv64, pos, sizeof (iv64)); + iv64 = FROM_BE64 (iv64); + obj->value.iv = iv64; len = 8; break; case msgpack_uint64: |