diff options
author | tnurnberg@mysql.com/white.intern.koehntopp.de <> | 2008-02-24 01:31:54 +0100 |
---|---|---|
committer | tnurnberg@mysql.com/white.intern.koehntopp.de <> | 2008-02-24 01:31:54 +0100 |
commit | 1ed076e41b47ca3114b308959d7544536044351d (patch) | |
tree | cd84aa795f9c47d4d5eff3b0deae320b06e2507a /sql/item_func.cc | |
parent | 730bea634f4ed85b20fa6fe0890c6b68e9e29537 (diff) | |
download | mariadb-git-1ed076e41b47ca3114b308959d7544536044351d.tar.gz |
Bug#20752: BENCHMARK with many iterations returns too quickly
In BENCHMARK(count, expr), count could overflow/wrap-around.
Patch changes to a sufficiently large data-type. Adds a warning
for negative count values.
Diffstat (limited to 'sql/item_func.cc')
-rw-r--r-- | sql/item_func.cc | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc index cd936412241..f6f67b148bd 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -3651,18 +3651,28 @@ longlong Item_func_benchmark::val_int() String tmp(buff,sizeof(buff), &my_charset_bin); my_decimal tmp_decimal; THD *thd=current_thd; - ulong loop_count; + ulonglong loop_count; - loop_count= (ulong) args[0]->val_int(); + loop_count= (ulonglong) args[0]->val_int(); - if (args[0]->null_value) + if (args[0]->null_value || + (!args[0]->unsigned_flag && (((longlong) loop_count) < 0))) { + if (!args[0]->null_value) + { + char buff[22]; + llstr(((longlong) loop_count), buff); + push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR, + ER_WRONG_VALUE_FOR_TYPE, ER(ER_WRONG_VALUE_FOR_TYPE), + "count", buff, "benchmark"); + } + null_value= 1; return 0; } null_value=0; - for (ulong loop=0 ; loop < loop_count && !thd->killed; loop++) + for (ulonglong loop=0 ; loop < loop_count && !thd->killed; loop++) { switch (args[1]->result_type()) { case REAL_RESULT: |