diff options
author | unknown <cbell/Chuck@mysql_cab_desk.> | 2007-09-14 11:22:41 -0400 |
---|---|---|
committer | unknown <cbell/Chuck@mysql_cab_desk.> | 2007-09-14 11:22:41 -0400 |
commit | 431fd2c1aaa4991ae6fe65f321f3ee84397cc0ef (patch) | |
tree | 842348f926dc278b89c6761445c922cfa60b6090 /sql/rpl_utility.cc | |
parent | 0e466b540cdcdb94fb438753e6f987c26fd9d0dd (diff) | |
download | mariadb-git-431fd2c1aaa4991ae6fe65f321f3ee84397cc0ef.tar.gz |
BUG#30790 : Suspicious code in rpl_utility.cc
This patch clarifies some of the coding choices with documentationa and
removes a limitation in the code for future expansion of the CHAR and
BINARY fields to length > 255.
sql/field.cc:
BUG#30790 : Suspicious code in rpl_utility.cc
This patch adds an assertion to ensure we are not attempting to encode
negative values.
sql/log_event.cc:
BUG#30790 : Suspicious code in rpl_utility.cc
This patch adds comments to help explain the choice of variable types.
sql/rpl_utility.cc:
BUG#30790 : Suspicious code in rpl_utility.cc
This patch removes code from the calc_field_size that is not needed and
was ambiguous. Originally intended to future expansion, the code was
not needed.
Also added are comments to help explain some portions of the code.
A change was made to the korr method to use the unsigned version to
avoid extended sign problems.
sql/rpl_utility.h:
BUG#30790 : Suspicious code in rpl_utility.cc
This patch corrects some type discrepencies and removes an extra cast.
Diffstat (limited to 'sql/rpl_utility.cc')
-rw-r--r-- | sql/rpl_utility.cc | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/sql/rpl_utility.cc b/sql/rpl_utility.cc index d1ce5bf3b7b..b3ca26d4c2c 100644 --- a/sql/rpl_utility.cc +++ b/sql/rpl_utility.cc @@ -31,31 +31,34 @@ uint32 table_def::calc_field_size(uint col, uchar *master_data) const switch (type(col)) { case MYSQL_TYPE_NEWDECIMAL: length= my_decimal_get_binary_size(m_field_metadata[col] >> 8, - m_field_metadata[col] - ((m_field_metadata[col] >> 8) << 8)); + m_field_metadata[col] & 0xff); break; case MYSQL_TYPE_DECIMAL: case MYSQL_TYPE_FLOAT: case MYSQL_TYPE_DOUBLE: length= m_field_metadata[col]; break; + /* + The cases for SET and ENUM are include for completeness, however + both are mapped to type MYSQL_TYPE_STRING and their real types + are encoded in the field metadata. + */ case MYSQL_TYPE_SET: case MYSQL_TYPE_ENUM: case MYSQL_TYPE_STRING: { - if (((m_field_metadata[col] & 0xff00) == (MYSQL_TYPE_SET << 8)) || - ((m_field_metadata[col] & 0xff00) == (MYSQL_TYPE_ENUM << 8))) + uchar type= m_field_metadata[col] >> 8U; + if ((type == MYSQL_TYPE_SET) || (type == MYSQL_TYPE_ENUM)) length= m_field_metadata[col] & 0x00ff; else { - length= m_field_metadata[col] & 0x00ff; - DBUG_ASSERT(length > 0); - if (length > 255) - { - DBUG_ASSERT(uint2korr(master_data) > 0); - length= uint2korr(master_data) + 2; - } - else - length= (uint) *master_data + 1; + /* + We are reading the actual size from the master_data record + because this field has the actual lengh stored in the first + byte. + */ + length= (uint) *master_data + 1; + DBUG_ASSERT(length != 0); } break; } @@ -95,6 +98,13 @@ uint32 table_def::calc_field_size(uint col, uchar *master_data) const break; case MYSQL_TYPE_BIT: { + /* + Decode the size of the bit field from the master. + from_len is the length in bytes from the master + from_bit_len is the number of extra bits stored in the master record + If from_bit_len is not 0, add 1 to the length to account for accurate + number of bytes needed. + */ uint from_len= (m_field_metadata[col] >> 8U) & 0x00ff; uint from_bit_len= m_field_metadata[col] & 0x00ff; DBUG_ASSERT(from_bit_len <= 7); @@ -136,7 +146,7 @@ uint32 table_def::calc_field_size(uint col, uchar *master_data) const length= *master_data; break; case 2: - length= sint2korr(master_data); + length= uint2korr(master_data); break; case 3: length= uint3korr(master_data); |