diff options
author | Oleksandr Byelkin <sanja@mariadb.com> | 2021-07-31 22:59:58 +0200 |
---|---|---|
committer | Oleksandr Byelkin <sanja@mariadb.com> | 2021-07-31 22:59:58 +0200 |
commit | 7841a7eb09208f52fcbab7e80e38c7ca29b1339e (patch) | |
tree | 7f9c4d80d3b86a33c54ff0090865ada4d4ed577d /sql/item_strfunc.cc | |
parent | 77992bc710bbc16798c12da7081769817f87791a (diff) | |
parent | 1423cf5e3dcb3c50047f086a5933fe77006cf242 (diff) | |
download | mariadb-git-7841a7eb09208f52fcbab7e80e38c7ca29b1339e.tar.gz |
Merge branch '10.3' into 10.4
Diffstat (limited to 'sql/item_strfunc.cc')
-rw-r--r-- | sql/item_strfunc.cc | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 759b18c4657..4f62452aa5a 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -500,7 +500,7 @@ err: const char *histogram_types[] = {"SINGLE_PREC_HB", "DOUBLE_PREC_HB", 0}; -static TYPELIB hystorgam_types_typelib= +static TYPELIB histogram_types_typelib= { array_elements(histogram_types), "histogram_types", histogram_types, NULL}; @@ -516,7 +516,7 @@ String *Item_func_decode_histogram::val_str(String *str) tmp.length(0); if (!(res= args[0]->val_str(&tmp)) || (type= find_type(res->c_ptr_safe(), - &hystorgam_types_typelib, MYF(0))) <= 0) + &histogram_types_typelib, MYF(0))) <= 0) { null_value= 1; return 0; @@ -601,7 +601,7 @@ bool Item_func_concat::realloc_result(String *str, uint length) const as str was initially set by args[0]->val_str(str). So multiplication by 2 can overflow, if args[0] for some reasons did not limit the result to max_alloced_packet. But it's not harmful, - "str" will be realloced exactly to "length" bytes in case of overflow. + "str" will be reallocated exactly to "length" bytes in case of overflow. */ uint new_length= MY_MAX(str->alloced_length() * 2, length); return str->realloc(new_length); @@ -1528,7 +1528,7 @@ String *Item_func_insert::val_str(String *str) start--; /* - There is one exception not handled (intentionaly) by the character set + There is one exception not handled (intentionally) by the character set aggregation code. If one string is strong side and is binary, and another one is weak side and is a multi-byte character string, then we need to operate on the second string in terms on bytes when @@ -3219,6 +3219,14 @@ err: } +static String *default_pad_str(String *pad_str, CHARSET_INFO *collation) +{ + pad_str->set_charset(collation); + pad_str->length(0); + pad_str->append(" ", 1); + return pad_str; +} + bool Item_func_pad::fix_length_and_dec() { if (arg_count == 3) @@ -3234,9 +3242,7 @@ bool Item_func_pad::fix_length_and_dec() { if (agg_arg_charsets_for_string_result(collation, &args[0], 1, 1)) return TRUE; - pad_str.set_charset(collation.collation); - pad_str.length(0); - pad_str.append(" ", 1); + default_pad_str(&pad_str, collation.collation); } DBUG_ASSERT(collation.collation->mbmaxlen > 0); @@ -3259,9 +3265,9 @@ bool Item_func_pad::fix_length_and_dec() Sql_mode_dependency Item_func_rpad::value_depends_on_sql_mode() const { DBUG_ASSERT(fixed); - DBUG_ASSERT(arg_count == 3); + DBUG_ASSERT(arg_count >= 2); if (!args[1]->value_depends_on_sql_mode_const_item() || - !args[2]->value_depends_on_sql_mode_const_item()) + (arg_count == 3 && !args[2]->value_depends_on_sql_mode_const_item())) return Item_func::value_depends_on_sql_mode(); Longlong_hybrid len= args[1]->to_longlong_hybrid(); if (args[1]->null_value || len.neg()) @@ -3269,7 +3275,8 @@ Sql_mode_dependency Item_func_rpad::value_depends_on_sql_mode() const if (len.abs() > 0 && len.abs() < args[0]->max_char_length()) return Item_func::value_depends_on_sql_mode(); StringBuffer<64> padstrbuf; - String *padstr= args[2]->val_str(&padstrbuf); + String *padstr= arg_count == 3 ? args[2]->val_str(&padstrbuf) : + default_pad_str(&padstrbuf, collation.collation); if (!padstr || !padstr->length()) return Sql_mode_dependency(); // will return NULL if (padstr->lengthsp() != 0) @@ -3309,7 +3316,7 @@ String *Item_func_rpad::val_str(String *str) if ((ulonglong) count > INT_MAX32) count= INT_MAX32; /* - There is one exception not handled (intentionaly) by the character set + There is one exception not handled (intentionally) by the character set aggregation code. If one string is strong side and is binary, and another one is weak side and is a multi-byte character string, then we need to operate on the second string in terms on bytes when @@ -3402,7 +3409,7 @@ String *Item_func_lpad::val_str(String *str) count= INT_MAX32; /* - There is one exception not handled (intentionaly) by the character set + There is one exception not handled (intentionally) by the character set aggregation code. If one string is strong side and is binary, and another one is weak side and is a multi-byte character string, then we need to operate on the second string in terms on bytes when @@ -4210,7 +4217,7 @@ longlong Item_func_uncompressed_length::val_int() 5 bytes long. res->c_ptr() is not used because: - we do not need \0 terminated string to get first 4 bytes - - c_ptr() tests simbol after string end (uninitialiozed memory) which + - c_ptr() tests simbol after string end (uninitialized memory) which confuse valgrind */ return uint4korr(res->ptr()) & 0x3FFFFFFF; |