diff options
author | Sergei Golubchik <serg@mariadb.org> | 2018-01-16 23:00:21 +0100 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2018-01-16 23:29:48 +0100 |
commit | 444587d8a3c4b91421cd4cfd7bda2e3f4d1aebe4 (patch) | |
tree | 2da20b69c9345c8b66b66863b743511bd59c4759 /include/my_compare.h | |
parent | 5e7593add405f07ac6a7d755ae1349fb1d2eafd4 (diff) | |
download | mariadb-git-444587d8a3c4b91421cd4cfd7bda2e3f4d1aebe4.tar.gz |
BIT field woes
* get_rec_bits() was always reading two bytes, even if the
bit field contained only of one byte
* In various places the code used field->pack_length() bytes
starting from field->ptr, while it should be field->pack_length_in_rec()
* Field_bit::key_cmp and Field_bit::cmp_max passed field_length as
an argument to memcmp(), but field_length is the number of bits!
Diffstat (limited to 'include/my_compare.h')
-rw-r--r-- | include/my_compare.h | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/include/my_compare.h b/include/my_compare.h index 0db22b593f4..87f0aa8f3ca 100644 --- a/include/my_compare.h +++ b/include/my_compare.h @@ -91,17 +91,19 @@ typedef struct st_HA_KEYSEG /* Key-portion */ #define size_to_store_key_length(length) ((length) < 255 ? 1 : 3) -#define get_rec_bits(bit_ptr, bit_ofs, bit_len) \ - (((((uint16) (bit_ptr)[1] << 8) | (uint16) (bit_ptr)[0]) >> (bit_ofs)) & \ - ((1 << (bit_len)) - 1)) - -#define set_rec_bits(bits, bit_ptr, bit_ofs, bit_len) \ -{ \ - (bit_ptr)[0]= ((bit_ptr)[0] & ~(((1 << (bit_len)) - 1) << (bit_ofs))) | \ - ((bits) << (bit_ofs)); \ - if ((bit_ofs) + (bit_len) > 8) \ - (bit_ptr)[1]= ((bit_ptr)[1] & ~((1 << ((bit_len) - 8 + (bit_ofs))) - 1)) | \ - ((bits) >> (8 - (bit_ofs))); \ +static inline uint16 get_rec_bits(const uchar *ptr, uchar ofs, uint len) +{ + uint16 val= ptr[0]; + if (ofs + len > 8) + val|= (uint16)(ptr[1]) << 8; + return (val >> ofs) & ((1 << len) - 1); +} + +static inline void set_rec_bits(uint16 bits, uchar *ptr, uchar ofs, uint len) +{ + ptr[0]= (ptr[0] & ~(((1 << len) - 1) << ofs)) | (bits << ofs); + if (ofs + len > 8) + ptr[1]= (ptr[1] & ~((1 << (len - 8 + ofs)) - 1)) | (bits >> (8 - ofs)); } #define clr_rec_bits(bit_ptr, bit_ofs, bit_len) \ |