summaryrefslogtreecommitdiff
path: root/sql/field.cc
diff options
context:
space:
mode:
authorserg@serg.mylan <>2004-08-19 11:21:08 +0200
committerserg@serg.mylan <>2004-08-19 11:21:08 +0200
commit8ef3cdc2f93417d53a8a7df94ba879b6fdc7544f (patch)
treec78fafa8231fbdbc5ba79dd5883af4dab3bf580b /sql/field.cc
parent754fafd28f49160d3f514ef53a0181bf13ec4e0d (diff)
downloadmariadb-git-8ef3cdc2f93417d53a8a7df94ba879b6fdc7544f.tar.gz
take dec. point into account in store_double_in_string
Diffstat (limited to 'sql/field.cc')
-rw-r--r--sql/field.cc18
1 files changed, 12 insertions, 6 deletions
diff --git a/sql/field.cc b/sql/field.cc
index 33717d99583..1b5c688fe7a 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -3716,7 +3716,7 @@ static void store_double_in_string_field(Field_str *field, uint32 field_length,
{
bool use_scientific_notation=TRUE;
char buff[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
- int length;
+ uint length;
if (field_length < 32 && nr > 1)
{
if (field->ceiling == 0)
@@ -3732,11 +3732,17 @@ static void store_double_in_string_field(Field_str *field, uint32 field_length,
}
use_scientific_notation= (field->ceiling < nr);
}
- length= sprintf(buff, "%-.*g",
- use_scientific_notation ? max(0,field_length-5) : field_length,
- nr);
- DBUG_ASSERT(length <= field_length);
- field->store(buff, (uint) length);
+ length= (uint)sprintf(buff, "%-.*g",
+ use_scientific_notation ? max(0,field_length-5) : field_length,
+ nr);
+ /*
+ +1 below is because "precision" in %g above means the
+ max. number of significant digits, not the output width.
+ Thus the width can be larger than number of significant digits by 1
+ (for decimal point)
+ */
+ DBUG_ASSERT(length <= field_length+1);
+ field->store(buff, min(length, field_length));
}
void Field_string::store(double nr)