From 2b3633c7bd510ceec656183f3c229cbad84458b9 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 28 Sep 2006 17:00:29 +0500 Subject: [PATCH] Fix for bug #22271: data casting may affect data stored in the next column(s?) Using wrong filling value may cause unneeded extra bit rewriting. Fix: use proper value to fill uneven bits. mysql-test/r/type_bit.result: Fix for bug #22271: data casting may affect data stored in the next column(s?) - test case. mysql-test/t/type_bit.test: Fix for bug #22271: data casting may affect data stored in the next column(s?) - test result. sql/field.cc: Fix for bug #22271: data casting may affect data stored in the next column(s?) - use ((1 << bit_len) - 1) instead of 0xff to fill uneven bits in order not to change other's bits. --- mysql-test/r/type_bit.result | 8 ++++++++ mysql-test/t/type_bit.test | 8 ++++++++ sql/field.cc | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/type_bit.result b/mysql-test/r/type_bit.result index f0ac00cedfa..bd58e83bb3f 100644 --- a/mysql-test/r/type_bit.result +++ b/mysql-test/r/type_bit.result @@ -602,4 +602,12 @@ NULL NULL 0 0 11111111 11111111 drop table bug15583; +create table t1(a bit(1), b smallint unsigned); +insert into t1 (b, a) values ('2', '1'); +Warnings: +Warning 1264 Out of range value adjusted for column 'a' at row 1 +select hex(a), b from t1; +hex(a) b +1 2 +drop table t1; End of 5.0 tests diff --git a/mysql-test/t/type_bit.test b/mysql-test/t/type_bit.test index 998f8f18fbe..d46ba667665 100644 --- a/mysql-test/t/type_bit.test +++ b/mysql-test/t/type_bit.test @@ -252,5 +252,13 @@ select hex(b + 0), bin(b + 0), oct(b + 0), hex(n), bin(n), oct(n) from bug15583; select conv(b, 10, 2), conv(b + 0, 10, 2) from bug15583; drop table bug15583; +# +# Bug #22271: data casting may affect data stored in the next column(s?) +# + +create table t1(a bit(1), b smallint unsigned); +insert into t1 (b, a) values ('2', '1'); +select hex(a), b from t1; +drop table t1; --echo End of 5.0 tests diff --git a/sql/field.cc b/sql/field.cc index 4860f6ea3da..d4bd23240e5 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -7921,7 +7921,7 @@ int Field_bit::store(const char *from, uint length, CHARSET_INFO *cs) (delta == -1 && (uchar) *from > ((1 << bit_len) - 1)) || (!bit_len && delta < 0)) { - set_rec_bits(0xff, bit_ptr, bit_ofs, bit_len); + set_rec_bits((1 << bit_len) - 1, bit_ptr, bit_ofs, bit_len); memset(ptr, 0xff, bytes_in_rec); if (table->in_use->really_abort_on_warning()) set_warning(MYSQL_ERROR::WARN_LEVEL_ERROR, ER_DATA_TOO_LONG, 1);