From 7a35ec71da4a05b30c8178500dbd3c8f57ba7434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Mon, 13 Feb 2017 09:30:30 +0200 Subject: [PATCH] Fix DECIMAL conversion The DECIMAL type was not correctly converted to positive integers. The 0x80 bit was set only for negative numbers when it needed to be XOR-ed for all values. --- server/core/mysql_binlog.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/server/core/mysql_binlog.c b/server/core/mysql_binlog.c index 0fa01d866..14e69f242 100644 --- a/server/core/mysql_binlog.c +++ b/server/core/mysql_binlog.c @@ -605,12 +605,11 @@ size_t unpack_decimal_field(uint8_t *ptr, uint8_t *metadata, double *val_float) int fbytes = fpart1 * 4 + dig_bytes[fpart2]; /** Remove the sign bit and store it locally */ - bool signed_int = (ptr[0] & 0x80); + bool negative = (ptr[0] & 0x80) == 0; + ptr[0] ^= 0x80; - if (!signed_int) + if (negative) { - ptr[0] |= 0x80; - for (int i = 0; i < ibytes; i++) { ptr[i] = ~ptr[i]; @@ -625,7 +624,7 @@ size_t unpack_decimal_field(uint8_t *ptr, uint8_t *metadata, double *val_float) int64_t val_i = unpack_bytes(ptr, ibytes); int64_t val_f = fbytes ? unpack_bytes(ptr + ibytes, fbytes) : 0; - if (!signed_int) + if (negative) { val_i = -val_i; val_f = -val_f;