From 423f37b92b79ba8a094c24ce985edd4abf0a1343 Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" <> Date: Tue, 11 May 2004 12:39:00 +0200 Subject: [PATCH] out-of-bound array access fixed --- mysql-test/r/type_float.result | 12 ++++++++++++ mysql-test/t/type_float.test | 6 ++++++ sql/field.cc | 6 ++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/type_float.result b/mysql-test/r/type_float.result index a0c0e0f5503..71ac229601d 100644 --- a/mysql-test/r/type_float.result +++ b/mysql-test/r/type_float.result @@ -105,6 +105,18 @@ select min(a) from t1; min(a) -0.010 drop table t1; +create table t1 (a float(200,100), b double(200,100)); +insert t1 values (1.0, 2.0); +select * from t1; +a b +1.000000000000000000000000000000 2.000000000000000000000000000000 +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` float(200,30) default NULL, + `b` double(200,30) default NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +drop table t1; create table t1 (f float(54)); ERROR 42000: Incorrect column specifier for column 'f' drop table if exists t1; diff --git a/mysql-test/t/type_float.test b/mysql-test/t/type_float.test index caccf31b32a..7d3b90aabeb 100644 --- a/mysql-test/t/type_float.test +++ b/mysql-test/t/type_float.test @@ -54,6 +54,12 @@ select a from t1 order by a; select min(a) from t1; drop table t1; +create table t1 (a float(200,100), b double(200,100)); +insert t1 values (1.0, 2.0); +select * from t1; +show create table t1; +drop table t1; + # Errors --error 1063 diff --git a/sql/field.cc b/sql/field.cc index fdf314972c8..edaa29dbaa0 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -2307,7 +2307,8 @@ int Field_float::store(double nr) } else { - max_value= (log_10[field_length]-1)/log_10[dec]; + uint tmp=min(field_length,array_elements(log_10)-1); + max_value= (log_10[tmp]-1)/log_10[dec]; /* The following comparison is needed to not get an overflow if nr is close to FLT_MAX @@ -2607,7 +2608,8 @@ int Field_double::store(double nr) } else { - max_value= (log_10[field_length]-1)/log_10[dec]; + uint tmp=min(field_length,array_elements(log_10)-1); + max_value= (log_10[tmp]-1)/log_10[dec]; if (fabs(nr) < DBL_MAX/10.0e+32) nr= floor(nr*log_10[dec]+0.5)/log_10[dec]; }