[MDEV-4895] Valgrind warnings (Conditional jump or move depends on uninitialised value) in Field_datetime::get_date on GREATEST(..) IS NULL Created: 2013-08-13  Updated: 2013-08-20  Resolved: 2013-08-20

Status: Closed
Project: MariaDB Server
Component/s: None
Affects Version/s: 10.0.3, 5.5.32, 5.3.12
Fix Version/s: 10.0.5, 5.5.33, 5.3.13

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Timour Katchaounov (Inactive)
Resolution: Fixed Votes: 0
Labels: valgrind

Issue Links:
Relates

 Description   

CREATE TABLE t1 (dt DATETIME NOT NULL) ENGINE=InnoDB;
# INSERT is unimportant, it just shows that the table doesn't have to be empty
INSERT INTO t1 VALUES (NOW()),(NOW());
SELECT * FROM t1 WHERE GREATEST( dt, '2012-12-21 12:12:12' ) IS NULL;

==22755== Thread 5:
==22755== Conditional jump or move depends on uninitialised value(s)
==22755==    at 0x6444B9: Field_datetime::get_date(st_mysql_time*, unsigned int) (field.cc:5928)
==22755==    by 0x58234F: Item_field::get_date(st_mysql_time*, unsigned int) (item.cc:2347)
==22755==    by 0x5CBB96: get_datetime_value(THD*, Item***, Item**, Item*, bool*) (item_cmpfunc.cc:891)
==22755==    by 0x5B7BC9: Item_func_min_max::get_date(st_mysql_time*, unsigned int) (item_func.cc:2459)
==22755==    by 0x5B82B1: Item_func_min_max::val_int() (item_func.cc:2577)
==22755==    by 0x59873E: Item::update_null_value() (item.h:955)
==22755==    by 0x5C4B98: Item_func::is_null() (item_func.h:163)
==22755==    by 0x5D8076: Item_func_isnull::val_int() (item_cmpfunc.cc:4624)
==22755==    by 0x5AF299: eval_const_cond(Item*) (item_func.cc:63)
==22755==    by 0x72D886: remove_eq_conds(THD*, Item*, Item::cond_result*) (sql_select.cc:13362)
==22755==    by 0x72CCAC: optimize_cond(JOIN*, Item*, List<TABLE_LIST>*, bool, Item::cond_result*, COND_EQUAL**) (sql_select.cc:13129)
==22755==    by 0x70D411: JOIN::optimize() (sql_select.cc:1019)
==22755==    by 0x7147A6: mysql_select(THD*, Item***, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) (sql_select.cc:2976)
==22755==    by 0x70B1E6: handle_select(THD*, st_lex*, select_result*, unsigned long) (sql_select.cc:288)
==22755==    by 0x696682: execute_sqlcom_select(THD*, TABLE_LIST*) (sql_parse.cc:5172)
==22755==    by 0x68D441: mysql_execute_command(THD*) (sql_parse.cc:2305)
==22755== Conditional jump or move depends on uninitialised value(s)
==22755==    at 0x6444D4: Field_datetime::get_date(st_mysql_time*, unsigned int) (field.cc:5930)
==22755==    by 0x58234F: Item_field::get_date(st_mysql_time*, unsigned int) (item.cc:2347)
==22755==    by 0x5CBB96: get_datetime_value(THD*, Item***, Item**, Item*, bool*) (item_cmpfunc.cc:891)
==22755==    by 0x5B7BC9: Item_func_min_max::get_date(st_mysql_time*, unsigned int) (item_func.cc:2459)
==22755==    by 0x5B82B1: Item_func_min_max::val_int() (item_func.cc:2577)
==22755==    by 0x59873E: Item::update_null_value() (item.h:955)
==22755==    by 0x5C4B98: Item_func::is_null() (item_func.h:163)
==22755==    by 0x5D8076: Item_func_isnull::val_int() (item_cmpfunc.cc:4624)
==22755==    by 0x5AF299: eval_const_cond(Item*) (item_func.cc:63)
==22755==    by 0x72D886: remove_eq_conds(THD*, Item*, Item::cond_result*) (sql_select.cc:13362)
==22755==    by 0x72CCAC: optimize_cond(JOIN*, Item*, List<TABLE_LIST>*, bool, Item::cond_result*, COND_EQUAL**) (sql_select.cc:13129)
==22755==    by 0x70D411: JOIN::optimize() (sql_select.cc:1019)
==22755==    by 0x7147A6: mysql_select(THD*, Item***, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) (sql_select.cc:2976)
==22755==    by 0x70B1E6: handle_select(THD*, st_lex*, select_result*, unsigned long) (sql_select.cc:288)
==22755==    by 0x696682: execute_sqlcom_select(THD*, TABLE_LIST*) (sql_parse.cc:5172)
==22755==    by 0x68D441: mysql_execute_command(THD*) (sql_parse.cc:2305)
==22755== Conditional jump or move depends on uninitialised value(s)
==22755==    at 0x6444DF: Field_datetime::get_date(st_mysql_time*, unsigned int) (field.cc:5930)
==22755==    by 0x58234F: Item_field::get_date(st_mysql_time*, unsigned int) (item.cc:2347)
==22755==    by 0x5CBB96: get_datetime_value(THD*, Item***, Item**, Item*, bool*) (item_cmpfunc.cc:891)
==22755==    by 0x5B7BC9: Item_func_min_max::get_date(st_mysql_time*, unsigned int) (item_func.cc:2459)
==22755==    by 0x5B82B1: Item_func_min_max::val_int() (item_func.cc:2577)
==22755==    by 0x59873E: Item::update_null_value() (item.h:955)
==22755==    by 0x5C4B98: Item_func::is_null() (item_func.h:163)
==22755==    by 0x5D8076: Item_func_isnull::val_int() (item_cmpfunc.cc:4624)
==22755==    by 0x5AF299: eval_const_cond(Item*) (item_func.cc:63)
==22755==    by 0x72D886: remove_eq_conds(THD*, Item*, Item::cond_result*) (sql_select.cc:13362)
==22755==    by 0x72CCAC: optimize_cond(JOIN*, Item*, List<TABLE_LIST>*, bool, Item::cond_result*, COND_EQUAL**) (sql_select.cc:13129)
==22755==    by 0x70D411: JOIN::optimize() (sql_select.cc:1019)
==22755==    by 0x7147A6: mysql_select(THD*, Item***, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) (sql_select.cc:2976)
==22755==    by 0x70B1E6: handle_select(THD*, st_lex*, select_result*, unsigned long) (sql_select.cc:288)
==22755==    by 0x696682: execute_sqlcom_select(THD*, TABLE_LIST*) (sql_parse.cc:5172)
==22755==    by 0x68D441: mysql_execute_command(THD*) (sql_parse.cc:2305)
==22755== Conditional jump or move depends on uninitialised value(s)
==22755==    at 0x5B7C35: Item_func_min_max::get_date(st_mysql_time*, unsigned int) (item_func.cc:2468)
==22755==    by 0x5B82B1: Item_func_min_max::val_int() (item_func.cc:2577)
==22755==    by 0x59873E: Item::update_null_value() (item.h:955)
==22755==    by 0x5C4B98: Item_func::is_null() (item_func.h:163)
==22755==    by 0x5D8076: Item_func_isnull::val_int() (item_cmpfunc.cc:4624)
==22755==    by 0x5AF299: eval_const_cond(Item*) (item_func.cc:63)
==22755==    by 0x72D886: remove_eq_conds(THD*, Item*, Item::cond_result*) (sql_select.cc:13362)
==22755==    by 0x72CCAC: optimize_cond(JOIN*, Item*, List<TABLE_LIST>*, bool, Item::cond_result*, COND_EQUAL**) (sql_select.cc:13129)
==22755==    by 0x70D411: JOIN::optimize() (sql_select.cc:1019)
==22755==    by 0x7147A6: mysql_select(THD*, Item***, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) (sql_select.cc:2976)
==22755==    by 0x70B1E6: handle_select(THD*, st_lex*, select_result*, unsigned long) (sql_select.cc:288)
==22755==    by 0x696682: execute_sqlcom_select(THD*, TABLE_LIST*) (sql_parse.cc:5172)
==22755==    by 0x68D441: mysql_execute_command(THD*) (sql_parse.cc:2305)
==22755==    by 0x6990FC: mysql_parse(THD*, char*, unsigned int, char const**) (sql_parse.cc:6173)
==22755==    by 0x68ABE5: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1243)
==22755==    by 0x689E83: do_command(THD*) (sql_parse.cc:923)
==22755== Conditional jump or move depends on uninitialised value(s)
==22755==    at 0x918686: unpack_time (my_time.c:1461)
==22755==    by 0x5B7C8D: Item_func_min_max::get_date(st_mysql_time*, unsigned int) (item_func.cc:2471)
==22755==    by 0x5B82B1: Item_func_min_max::val_int() (item_func.cc:2577)
==22755==    by 0x59873E: Item::update_null_value() (item.h:955)
==22755==    by 0x5C4B98: Item_func::is_null() (item_func.h:163)
==22755==    by 0x5D8076: Item_func_isnull::val_int() (item_cmpfunc.cc:4624)
==22755==    by 0x5AF299: eval_const_cond(Item*) (item_func.cc:63)
==22755==    by 0x72D886: remove_eq_conds(THD*, Item*, Item::cond_result*) (sql_select.cc:13362)
==22755==    by 0x72CCAC: optimize_cond(JOIN*, Item*, List<TABLE_LIST>*, bool, Item::cond_result*, COND_EQUAL**) (sql_select.cc:13129)
==22755==    by 0x70D411: JOIN::optimize() (sql_select.cc:1019)
==22755==    by 0x7147A6: mysql_select(THD*, Item***, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) (sql_select.cc:2976)
==22755==    by 0x70B1E6: handle_select(THD*, st_lex*, select_result*, unsigned long) (sql_select.cc:288)
==22755==    by 0x696682: execute_sqlcom_select(THD*, TABLE_LIST*) (sql_parse.cc:5172)
==22755==    by 0x68D441: mysql_execute_command(THD*) (sql_parse.cc:2305)
==22755==    by 0x6990FC: mysql_parse(THD*, char*, unsigned int, char const**) (sql_parse.cc:6173)
==22755==    by 0x68ABE5: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1243)
==22755== Conditional jump or move depends on uninitialised value(s)
==22755==    at 0x7D61D3: non_zero_date(st_mysql_time const*) (mysql_priv.h:2564)
==22755==    by 0x7D6218: check_date(st_mysql_time const*, unsigned long long, int*) (mysql_priv.h:2569)
==22755==    by 0x7D68D6: check_date_with_warn(st_mysql_time const*, unsigned int, enum_mysql_timestamp_type) (time.cc:221)
==22755==    by 0x5B7CAD: Item_func_min_max::get_date(st_mysql_time*, unsigned int) (item_func.cc:2475)
==22755==    by 0x5B82B1: Item_func_min_max::val_int() (item_func.cc:2577)
==22755==    by 0x59873E: Item::update_null_value() (item.h:955)
==22755==    by 0x5C4B98: Item_func::is_null() (item_func.h:163)
==22755==    by 0x5D8076: Item_func_isnull::val_int() (item_cmpfunc.cc:4624)
==22755==    by 0x5AF299: eval_const_cond(Item*) (item_func.cc:63)
==22755==    by 0x72D886: remove_eq_conds(THD*, Item*, Item::cond_result*) (sql_select.cc:13362)
==22755==    by 0x72CCAC: optimize_cond(JOIN*, Item*, List<TABLE_LIST>*, bool, Item::cond_result*, COND_EQUAL**) (sql_select.cc:13129)
==22755==    by 0x70D411: JOIN::optimize() (sql_select.cc:1019)
==22755==    by 0x7147A6: mysql_select(THD*, Item***, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) (sql_select.cc:2976)
==22755==    by 0x70B1E6: handle_select(THD*, st_lex*, select_result*, unsigned long) (sql_select.cc:288)
==22755==    by 0x696682: execute_sqlcom_select(THD*, TABLE_LIST*) (sql_parse.cc:5172)
==22755==    by 0x68D441: mysql_execute_command(THD*) (sql_parse.cc:2305)
==22755== Conditional jump or move depends on uninitialised value(s)
==22755==    at 0x915853: check_date (my_time.c:87)
==22755==    by 0x7D622F: check_date(st_mysql_time const*, unsigned long long, int*) (mysql_priv.h:2569)
==22755==    by 0x7D68D6: check_date_with_warn(st_mysql_time const*, unsigned int, enum_mysql_timestamp_type) (time.cc:221)
==22755==    by 0x5B7CAD: Item_func_min_max::get_date(st_mysql_time*, unsigned int) (item_func.cc:2475)
==22755==    by 0x5B82B1: Item_func_min_max::val_int() (item_func.cc:2577)
==22755==    by 0x59873E: Item::update_null_value() (item.h:955)
==22755==    by 0x5C4B98: Item_func::is_null() (item_func.h:163)
==22755==    by 0x5D8076: Item_func_isnull::val_int() (item_cmpfunc.cc:4624)
==22755==    by 0x5AF299: eval_const_cond(Item*) (item_func.cc:63)
==22755==    by 0x72D886: remove_eq_conds(THD*, Item*, Item::cond_result*) (sql_select.cc:13362)
==22755==    by 0x72CCAC: optimize_cond(JOIN*, Item*, List<TABLE_LIST>*, bool, Item::cond_result*, COND_EQUAL**) (sql_select.cc:13129)
==22755==    by 0x70D411: JOIN::optimize() (sql_select.cc:1019)
==22755==    by 0x7147A6: mysql_select(THD*, Item***, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) (sql_select.cc:2976)
==22755==    by 0x70B1E6: handle_select(THD*, st_lex*, select_result*, unsigned long) (sql_select.cc:288)
==22755==    by 0x696682: execute_sqlcom_select(THD*, TABLE_LIST*) (sql_parse.cc:5172)
==22755==    by 0x68D441: mysql_execute_command(THD*) (sql_parse.cc:2305)
==22755== Conditional jump or move depends on uninitialised value(s)
==22755==    at 0x91586C: check_date (my_time.c:88)
==22755==    by 0x7D622F: check_date(st_mysql_time const*, unsigned long long, int*) (mysql_priv.h:2569)
==22755==    by 0x7D68D6: check_date_with_warn(st_mysql_time const*, unsigned int, enum_mysql_timestamp_type) (time.cc:221)
==22755==    by 0x5B7CAD: Item_func_min_max::get_date(st_mysql_time*, unsigned int) (item_func.cc:2475)
==22755==    by 0x5B82B1: Item_func_min_max::val_int() (item_func.cc:2577)
==22755==    by 0x59873E: Item::update_null_value() (item.h:955)
==22755==    by 0x5C4B98: Item_func::is_null() (item_func.h:163)
==22755==    by 0x5D8076: Item_func_isnull::val_int() (item_cmpfunc.cc:4624)
==22755==    by 0x5AF299: eval_const_cond(Item*) (item_func.cc:63)
==22755==    by 0x72D886: remove_eq_conds(THD*, Item*, Item::cond_result*) (sql_select.cc:13362)
==22755==    by 0x72CCAC: optimize_cond(JOIN*, Item*, List<TABLE_LIST>*, bool, Item::cond_result*, COND_EQUAL**) (sql_select.cc:13129)
==22755==    by 0x70D411: JOIN::optimize() (sql_select.cc:1019)
==22755==    by 0x7147A6: mysql_select(THD*, Item***, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) (sql_select.cc:2976)
==22755==    by 0x70B1E6: handle_select(THD*, st_lex*, select_result*, unsigned long) (sql_select.cc:288)
==22755==    by 0x696682: execute_sqlcom_select(THD*, TABLE_LIST*) (sql_parse.cc:5172)
==22755==    by 0x68D441: mysql_execute_command(THD*) (sql_parse.cc:2305)
==22755== Use of uninitialised value of size 8
==22755==    at 0x915881: check_date (my_time.c:89)
==22755==    by 0x7D622F: check_date(st_mysql_time const*, unsigned long long, int*) (mysql_priv.h:2569)
==22755==    by 0x7D68D6: check_date_with_warn(st_mysql_time const*, unsigned int, enum_mysql_timestamp_type) (time.cc:221)
==22755==    by 0x5B7CAD: Item_func_min_max::get_date(st_mysql_time*, unsigned int) (item_func.cc:2475)
==22755==    by 0x5B82B1: Item_func_min_max::val_int() (item_func.cc:2577)
==22755==    by 0x59873E: Item::update_null_value() (item.h:955)
==22755==    by 0x5C4B98: Item_func::is_null() (item_func.h:163)
==22755==    by 0x5D8076: Item_func_isnull::val_int() (item_cmpfunc.cc:4624)
==22755==    by 0x5AF299: eval_const_cond(Item*) (item_func.cc:63)
==22755==    by 0x72D886: remove_eq_conds(THD*, Item*, Item::cond_result*) (sql_select.cc:13362)
==22755==    by 0x72CCAC: optimize_cond(JOIN*, Item*, List<TABLE_LIST>*, bool, Item::cond_result*, COND_EQUAL**) (sql_select.cc:13129)
==22755==    by 0x70D411: JOIN::optimize() (sql_select.cc:1019)
==22755==    by 0x7147A6: mysql_select(THD*, Item***, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) (sql_select.cc:2976)
==22755==    by 0x70B1E6: handle_select(THD*, st_lex*, select_result*, unsigned long) (sql_select.cc:288)
==22755==    by 0x696682: execute_sqlcom_select(THD*, TABLE_LIST*) (sql_parse.cc:5172)
==22755==    by 0x68D441: mysql_execute_command(THD*) (sql_parse.cc:2305)
==22755== Conditional jump or move depends on uninitialised value(s)
==22755==    at 0x91588D: check_date (my_time.c:89)
==22755==    by 0x7D622F: check_date(st_mysql_time const*, unsigned long long, int*) (mysql_priv.h:2569)
==22755==    by 0x7D68D6: check_date_with_warn(st_mysql_time const*, unsigned int, enum_mysql_timestamp_type) (time.cc:221)
==22755==    by 0x5B7CAD: Item_func_min_max::get_date(st_mysql_time*, unsigned int) (item_func.cc:2475)
==22755==    by 0x5B82B1: Item_func_min_max::val_int() (item_func.cc:2577)
==22755==    by 0x59873E: Item::update_null_value() (item.h:955)
==22755==    by 0x5C4B98: Item_func::is_null() (item_func.h:163)
==22755==    by 0x5D8076: Item_func_isnull::val_int() (item_cmpfunc.cc:4624)
==22755==    by 0x5AF299: eval_const_cond(Item*) (item_func.cc:63)
==22755==    by 0x72D886: remove_eq_conds(THD*, Item*, Item::cond_result*) (sql_select.cc:13362)
==22755==    by 0x72CCAC: optimize_cond(JOIN*, Item*, List<TABLE_LIST>*, bool, Item::cond_result*, COND_EQUAL**) (sql_select.cc:13129)
==22755==    by 0x70D411: JOIN::optimize() (sql_select.cc:1019)
==22755==    by 0x7147A6: mysql_select(THD*, Item***, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) (sql_select.cc:2976)
==22755==    by 0x70B1E6: handle_select(THD*, st_lex*, select_result*, unsigned long) (sql_select.cc:288)
==22755==    by 0x696682: execute_sqlcom_select(THD*, TABLE_LIST*) (sql_parse.cc:5172)
==22755==    by 0x68D441: mysql_execute_command(THD*) (sql_parse.cc:2305)

bzr version-info

revision-id: bar@mariadb.org-20130812124759-8cy7ot1s3ysgned2
revno: 3674
branch-nick: 5.3

Built with BUILD/compile-pentium-valgrind-max-no-ndb

Also reproducible on 5.5, 10.0.



 Comments   
Comment by Alexander Barkov [ 2013-08-16 ]

The problem is also repeatable with ENGINE=MyISAM and ENGINE=HEAP.

Comment by Alexander Barkov [ 2013-08-16 ]

The problem is also repeatable with other functions, e.g. CONCAT:

drop table if exists t1;
CREATE TABLE t1 (dt DATETIME NOT NULL);
INSERT INTO t1 VALUES (NOW()),(NOW());
SELECT * FROM t1 WHERE concat( dt, '2012-12-21 12:12:12' ) IS NULL;

And with other column types:

drop table if exists t1;
CREATE TABLE t1 (dt INT NOT NULL);
INSERT INTO t1 VALUES (1),(2);
SELECT * FROM t1 WHERE concat( dt, '1' ) IS NULL;

and with a more complex condition:

drop table if exists t1;
CREATE TABLE t1 (dt INT NOT NULL);
INSERT INTO t1 VALUES (1),(2);
SELECT * FROM t1 WHERE NOT (concat( dt, '1' ) IS NOT NULL);

Comment by Alexander Barkov [ 2013-08-16 ]

The problem was introduced by revno 2800.2.8 in 5.3 tree.

See this command for details:

bzr log -c 2800.2.8 ; bzr diff -c 2800.2.8

Comment by Alexander Barkov [ 2013-08-16 ]

5.2 built with "./BUILD/compile-pentium-valgrind-max-no-ndb" is not affected.

Comment by Timour Katchaounov (Inactive) [ 2013-08-19 ]

According to Bar the cause is " val_int is called on a field which does not have a valid record yet".
If so, then the most likely solution is not to call eval_const_cond() in this case.

Comment by Alexander Barkov [ 2013-08-20 ]

Should not this patch fix the problem:

longlong Item_func_isnotnull::val_int()
{
DBUG_ASSERT(fixed == 1);
< return args[0]->is_null() ? 0 : 1;
> return args[0]>maybe_null ? args[0]>is_null() ? 0 : 1 : 0;
}

Comment by Alexander Barkov [ 2013-08-20 ]

MDEV-4915 has been marked as a duplicate for this report.

Comment by Timour Katchaounov (Inactive) [ 2013-08-20 ]

Pushed to 5.3.

Generated at Thu Feb 08 07:00:01 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.