diff --git a/mysql-test/r/variables.result b/mysql-test/r/variables.result index 6b700f7f6a2..633f7c139fd 100644 --- a/mysql-test/r/variables.result +++ b/mysql-test/r/variables.result @@ -482,3 +482,8 @@ SET GLOBAL MYISAM_DATA_POINTER_SIZE= 8; SHOW VARIABLES LIKE 'MYISAM_DATA_POINTER_SIZE'; Variable_name Value myisam_data_pointer_size 8 +SET GLOBAL table_cache=-1; +SHOW VARIABLES LIKE 'table_cache'; +Variable_name Value +table_cache 1 +SET GLOBAL table_cache=DEFAULT; diff --git a/mysql-test/t/variables.test b/mysql-test/t/variables.test index 3a76ae5136e..f80ca6378a1 100644 --- a/mysql-test/t/variables.test +++ b/mysql-test/t/variables.test @@ -362,3 +362,11 @@ drop table t1; SET GLOBAL MYISAM_DATA_POINTER_SIZE= 8; SHOW VARIABLES LIKE 'MYISAM_DATA_POINTER_SIZE'; + +# +# Bug #6958: negative arguments to integer options wrap around +# + +SET GLOBAL table_cache=-1; +SHOW VARIABLES LIKE 'table_cache'; +SET GLOBAL table_cache=DEFAULT; diff --git a/sql/set_var.cc b/sql/set_var.cc index ca7987d2636..7f393363ed6 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -1223,6 +1223,12 @@ static void fix_server_id(THD *thd, enum_var_type type) server_id_supplied = 1; } +bool sys_var_long_ptr::check(THD *thd, set_var *var) +{ + longlong v= var->value->val_int(); + var->save_result.ulonglong_value= v < 0 ? 0 : v; + return 0; +} bool sys_var_long_ptr::update(THD *thd, set_var *var) { diff --git a/sql/set_var.h b/sql/set_var.h index df2fd41c7bd..080a2a95ae0 100644 --- a/sql/set_var.h +++ b/sql/set_var.h @@ -93,6 +93,7 @@ public: sys_var_long_ptr(const char *name_arg, ulong *value_ptr, sys_after_update_func func) :sys_var(name_arg,func), value(value_ptr) {} + bool check(THD *thd, set_var *var); bool update(THD *thd, set_var *var); void set_default(THD *thd, enum_var_type type); SHOW_TYPE type() { return SHOW_LONG; }