diff --git a/mysql-test/main/func_str.result b/mysql-test/main/func_str.result index 2d79f741871..88429defc40 100644 --- a/mysql-test/main/func_str.result +++ b/mysql-test/main/func_str.result @@ -5327,5 +5327,20 @@ SELECT RANDOM_BYTES(-10) f1, IFNULL(a,1) f2 FROM t GROUP BY f1, f2; ERROR 22003: length value is out of range in 'random_bytes(-10)' DROP TABLE t; # +# MDEV-29154: Excessive warnings upon a call to RANDOM_BYTES +# +select length(random_bytes(cast('x' as unsigned)+1)); +length(random_bytes(cast('x' as unsigned)+1)) +1 +Warnings: +Warning 1292 Truncated incorrect INTEGER value: 'x' +Warning 1292 Truncated incorrect INTEGER value: 'x' +select repeat('.', cast('x' as unsigned)+1); +repeat('.', cast('x' as unsigned)+1) +. +Warnings: +Warning 1292 Truncated incorrect INTEGER value: 'x' +Warning 1292 Truncated incorrect INTEGER value: 'x' +# # End of 10.10 tests # diff --git a/mysql-test/main/func_str.test b/mysql-test/main/func_str.test index f44adfee23d..c8546e474d1 100644 --- a/mysql-test/main/func_str.test +++ b/mysql-test/main/func_str.test @@ -2259,6 +2259,13 @@ SELECT RANDOM_BYTES(-10) f1, IFNULL(a,1) f2 FROM t GROUP BY f1, f2; # Cleanup DROP TABLE t; +--echo # +--echo # MDEV-29154: Excessive warnings upon a call to RANDOM_BYTES +--echo # + +select length(random_bytes(cast('x' as unsigned)+1)); +select repeat('.', cast('x' as unsigned)+1); + --echo # --echo # End of 10.10 tests --echo # diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 692ffbd85e9..1a78efce0dc 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1478,14 +1478,13 @@ String *Item_func_sformat::val_str(String *res) #include #include -static const int MAX_RANDOM_BYTES= 1024; - bool Item_func_random_bytes::fix_length_and_dec(THD *thd) { used_tables_cache|= RAND_TABLE_BIT; if (args[0]->can_eval_in_optimize()) { - max_length= MY_MAX(0, MY_MIN((int32) args[0]->val_int(), MAX_RANDOM_BYTES)); + int32 v= (int32) args[0]->val_int(); + max_length= MY_MAX(0, MY_MIN(v, MAX_RANDOM_BYTES)); return false; } max_length= MAX_RANDOM_BYTES; diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index 7df64627d41..11b9b873c88 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -406,6 +406,7 @@ public: { return get_item_copy(thd, this); } + static const int MAX_RANDOM_BYTES= 1024; };