mirror of
https://github.com/MariaDB/server.git
synced 2025-08-09 22:24:09 +03:00
MDEV-29152: Assertion failed ... upon TO_CHAR with wrong argument
Item_func_tochar::check_arguments() didn't check if its arguments each had one column. Failing to make this check and proceeding would eventually cause either an assertion failure or the execution would reach "MY_ASSERT_UNREACHABLE();" which would produce a crash with a misleading stack trace. * Fixed Item_func_tochar::check_arguments() to do the required check. * Also fixed MY_ASSERT_UNREACHABLE() to terminate the program. Just "executing" __builtin_unreachable() used to cause "undefined results", which in my experience was a crash with corrupted stack trace.
This commit is contained in:
@@ -40,7 +40,15 @@
|
||||
/* GNU C/C++ */
|
||||
#if defined __GNUC__
|
||||
# define MY_ALIGN_EXT
|
||||
# define MY_ASSERT_UNREACHABLE() __builtin_unreachable()
|
||||
|
||||
/*
|
||||
__builtin_unreachable() removes the "statement may fall through" warning-as-
|
||||
error when MY_ASSERT_UNREACHABLE() is used in "case xxx:" in switch (...)
|
||||
statements.
|
||||
abort() is there to prevent the execution from reaching the
|
||||
__builtin_unreachable() as this may cause misleading stack traces.
|
||||
*/
|
||||
# define MY_ASSERT_UNREACHABLE() { abort(); __builtin_unreachable(); }
|
||||
|
||||
/* Microsoft Visual C++ */
|
||||
#elif defined _MSC_VER
|
||||
@@ -88,7 +96,7 @@
|
||||
#endif
|
||||
|
||||
#ifndef MY_ASSERT_UNREACHABLE
|
||||
# define MY_ASSERT_UNREACHABLE() do { assert(0); } while (0)
|
||||
# define MY_ASSERT_UNREACHABLE() do { abort(); } while (0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@@ -439,3 +439,10 @@ NULL
|
||||
NULL
|
||||
2021-01-24
|
||||
drop table t1,t2;
|
||||
set @local.sql_mode=@sql_mode;
|
||||
#
|
||||
# MDEV-29152: Assertion failed ... upon TO_CHAR with wrong argument
|
||||
#
|
||||
SELECT TO_CHAR((VALUES('2022-12-12','2020-10-10')));
|
||||
ERROR HY000: Illegal parameter data type row for operation 'to_char'
|
||||
SELECT TO_CHAR((STR_TO_DATE('2023-01-01', '%d-%m-%Y'), 'YYYY-MM-DD') );
|
||||
|
@@ -224,3 +224,13 @@ select * from t2;
|
||||
drop table t1,t2;
|
||||
set @local.sql_mode=@sql_mode;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-29152: Assertion failed ... upon TO_CHAR with wrong argument
|
||||
--echo #
|
||||
|
||||
--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
|
||||
SELECT TO_CHAR((VALUES('2022-12-12','2020-10-10')));
|
||||
|
||||
--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
|
||||
SELECT TO_CHAR((STR_TO_DATE('2023-01-01', '%d-%m-%Y'), 'YYYY-MM-DD') );
|
||||
|
||||
|
@@ -996,7 +996,10 @@ class Item_func_tochar :public Item_str_func
|
||||
|
||||
bool check_arguments() const override
|
||||
{
|
||||
return check_argument_types_can_return_text(1, arg_count);
|
||||
return
|
||||
(args[0]->check_type_can_return_date(func_name_cstring()) &&
|
||||
args[0]->check_type_can_return_time(func_name_cstring())) ||
|
||||
check_argument_types_can_return_text(1, arg_count);
|
||||
}
|
||||
|
||||
public:
|
||||
|
Reference in New Issue
Block a user