diff options
author | unknown <serg@serg.mylan> | 2004-08-20 00:52:43 +0200 |
---|---|---|
committer | unknown <serg@serg.mylan> | 2004-08-20 00:52:43 +0200 |
commit | 04c39153435896d9f49fe1b5b80bd7e11edf7bf4 (patch) | |
tree | 5fff92365d8baf56b0bfb2391843398321d56ee2 /sql/field.cc | |
parent | 6e1b567ab3afd324606918ebc30f5205aacdc14a (diff) | |
parent | d1c5ca31f615592f62280ef2d005fa1201541027 (diff) | |
download | mariadb-git-04c39153435896d9f49fe1b5b80bd7e11edf7bf4.tar.gz |
merged
BitKeeper/etc/ignore:
auto-union
include/my_global.h:
Auto merged
mysys/mf_tempfile.c:
Auto merged
mysql-test/r/rpl_heap.result:
Auto merged
mysql-test/t/rpl_heap.test:
Auto merged
sql/ha_innodb.cc:
Auto merged
Diffstat (limited to 'sql/field.cc')
-rw-r--r-- | sql/field.cc | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/sql/field.cc b/sql/field.cc index 522daa9e2cd..96f4fa8fd86 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -4279,7 +4279,7 @@ int Field_str::store(double nr) { bool use_scientific_notation=TRUE; char buff[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE]; - int length; + uint length; if (field_length < 32 && nr > 1) // TODO: negative numbers { if (ceiling == 0) @@ -4295,11 +4295,19 @@ int Field_str::store(double nr) } use_scientific_notation= (ceiling < nr); } - length= sprintf(buff, "%-.*g", - use_scientific_notation ? max(0,field_length-5) : field_length, - nr); - DBUG_ASSERT(length <= field_length); - return store((const char *)buff, (uint) length, charset()); + length= (uint)sprintf(buff, "%-.*g", + use_scientific_notation ? max(0,(int)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) + the test for field_length < 5 is for extreme cases, + like inserting 500.0 in char(1) + */ + DBUG_ASSERT(field_length < 5 || length <= field_length+1); + return store((const char *)buff, min(length, field_length), charset()); } int Field_string::store(longlong nr) |