Commit graph

39 commits

Author SHA1 Message Date
Alexander Barkov
b777b749ad MDEV-28345 ASAN: use-after-poison or unknown-crash in my_strtod_int from charset_info_st::strntod or test_if_number
This patch fixes two problems:

- The code inside my_strtod_int() in strings/dtoa.c could test the byte
  behind the end of the string when processing the mantissa.
  Rewriting the code to avoid this.

- The code in test_if_number() in sql/sql_analyse.cc called my_atof()
  which is unsafe and makes the called my_strtod_int() look behind
  the end of the string if the input string is not 0-terminated.
  Fixing test_if_number() to use my_strtod() instead, passing the correct
  end pointer.
2024-07-17 12:17:27 +04:00
Marko Mäkelä
1dc2f35598 Merge 10.4 into 10.5 2022-12-13 14:39:18 +02:00
Alexander Barkov
6216a2dfa2 MDEV-29473 UBSAN: Signed integer overflow: X * Y cannot be represented in type 'int' in strings/dtoa.c
Fixing a few problems relealed by UBSAN in type_float.test

- multiplication overflow in dtoa.c

- uninitialized Field::geom_type (and Field::srid as well)

- Wrong call-back function types used in combination with SHOW_FUNC.
  Changes in the mysql_show_var_func data type definition were not
  properly addressed all around the code by the following commits:
    b4ff64568c
    18feb62fee
    0ee879ff8a

  Adding a helper SHOW_FUNC_ENTRY() function and replacing
  all mysql_show_var_func declarations using SHOW_FUNC
  to SHOW_FUNC_ENTRY, to catch mysql_show_var_func in the future
  at compilation time.
2022-11-17 17:51:01 +04:00
Monty
e843033d02 Created a workaround for a bug in MSAN for va_arg(,double)
MDEV-22691 MSAN use-of-uninitialized-value in test maria.maria-recovery2

This caused all my_vsnprintf() using doubles to fail.
Thanks to the workaround, I was able to remove the disabling of
MSAN in dtoa().
2020-06-14 19:39:43 +03:00
Marko Mäkelä
94d0bb4dbe MDEV-20377: Make WITH_MSAN more usable
MemorySanitizer (clang -fsanitize=memory) requires that all code
be compiled with instrumentation enabled. The C runtime library
is an exception. Failure to use instrumented libraries will cause
bogus messages about memory being uninitialized.

In WITH_MSAN builds, we must avoid calling getservbyname(),
because even though it is a standard library function, it is
not instrumented, not even in clang 10.

The following cmake options were tested:

-DCMAKE_C_FLAGS='-march=native -O2'
-DCMAKE_CXX_FLAGS='-stdlib=libc++ -march=native -O2'
-DWITH_EMBEDDED_SERVER=OFF -DWITH_UNIT_TESTS=OFF -DCMAKE_BUILD_TYPE=Debug
-DWITH_INNODB_{BZIP2,LZ4,LZMA,LZO,SNAPPY}=OFF
-DPLUGIN_{ARCHIVE,TOKUDB,MROONGA,OQGRAPH,ROCKSDB,CONNECT,SPIDER}=NO
-DWITH_SAFEMALLOC=OFF
-DWITH_{ZLIB,SSL,PCRE}=bundled
-DHAVE_LIBAIO_H=0
-DWITH_MSAN=ON

MEM_MAKE_DEFINED(): An alias for VALGRIND_MAKE_MEM_DEFINED()
and in the future, __msan_unpoison().

For now, neither MEM_MAKE_DEFINED() nor MEM_UNDEFINED()
perform any action under MSAN. Enabling them will catch more bugs, but
will also require some more fixes or work-arounds.

Json_writer::add_double(): Work around a frequently occurring
failure in optimizer tests, related to EXPLAIN FORMAT=JSON.

dtoa(): Disable MSAN altogether. For some reason, this function
is triggering a lot of trouble, especially when invoked for
DBUG functions. The MDL default timeout is dd=86400 seconds,
and for some reason it is claimed to be uninitialized.

InnoDB: Define UNIV_DEBUG_VALGRIND also WITH_MSAN.

ut_crc32_8_hw(), ut_crc32_64_low_hw(): Use the compiler built-in
functions instead of inline assembler when building WITH_MSAN.
This will require at least -msse4.2 when building for IA-32 or AMD64.
The inline assembler would not be instrumented, and would thus cause
bogus failures.
2020-03-28 21:36:30 +02:00
Marko Mäkelä
be85d3e61b Merge 10.2 into 10.3 2019-05-14 17:18:46 +03:00
Marko Mäkelä
26a14ee130 Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
Vicențiu Ciorbaru
cb248f8806 Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
Vicențiu Ciorbaru
5543b75550 Update FSF Address
* Update wrong zip-code
2019-05-11 21:29:06 +03:00
luz.paz
3dd01669b4 Misc. typos
Found via `codespell -i 3 -w --skip="./debian/po" -I ../mariadb-server-word-whitelist.txt  ./cmake/ ./debian/ ./Docs/ ./include/ ./man/ ./plugin/ ./strings/`
2018-04-05 15:26:57 +04:00
Vladislav Vaintroub
7a01e64c3a Fix warnings 2018-01-06 22:11:42 +00:00
Vicențiu Ciorbaru
b2a102fb58 Fix double floating point error in dtoa.c
When running an optimized build, compiler optimizations cause loss of
precision unless we force the expression to use a double type.
2017-12-30 00:20:58 +02:00
Sergei Golubchik
e0a1c745ec Merge branch '10.1' into 10.2 2017-10-24 14:53:18 +02:00
Sergei Golubchik
da4503e956 Merge branch '5.5' into 10.0 2017-10-18 15:14:39 +02:00
Sergei Golubchik
d76f5774fe MDEV-13459 Warnings, when compiling with gcc-7.x
mostly caused by -Wimplicit-fallthrough
2017-10-17 07:37:39 +02:00
Vladislav Vaintroub
7354dc6773 MDEV-13384 - misc Windows warnings fixed 2017-09-28 17:20:46 +00:00
Marko Mäkelä
70505dd45b Merge 10.1 into 10.2 2017-05-22 09:46:51 +03:00
Marko Mäkelä
71cd205956 Silence bogus GCC 7 warnings -Wimplicit-fallthrough
Do not silence uncertain cases, or fix any bugs.

The only functional change should be that ha_federated::extra()
is not calling DBUG_PRINT to report an unhandled case for
HA_EXTRA_PREPARE_FOR_DROP.
2017-05-17 08:27:04 +03:00
Marko Mäkelä
7972da8aa1 Silence bogus GCC 7 warnings -Wimplicit-fallthrough
Do not silence uncertain cases, or fix any bugs.

The only functional change should be that ha_federated::extra()
is not calling DBUG_PRINT to report an unhandled case for
HA_EXTRA_PREPARE_FOR_DROP.
2017-05-17 08:07:02 +03:00
Monty
34eb10e406 MDEV-10138 Support for decimals up to 38 digits
Decimals with float, double and decimal now works the following way:

- DECIMAL_NOT_SPECIFIED is used when declaring DECIMALS without a firm number
  of decimals.  It's only used in asserts and my_decimal_int_part.
- FLOATING_POINT_DECIMALS (31) is used to mark that a FLOAT or DOUBLE
  was defined without decimals. This is regarded as a floating point value.
- Max decimals allowed for FLOAT and DOUBLE is FLOATING_POINT_DECIMALS-1
- Clients assumes that float and double with decimals >= NOT_FIXED_DEC are
  floating point values (no decimals)
- In the .frm decimals=FLOATING_POINT_DECIMALS are used to define
  floating point for float and double (31, like before)

To ensure compatibility with old clients we do:

- When storing float and double, we change NOT_FIXED_DEC to
  FLOATING_POINT_DECIMALS.
- When creating fields from .frm we change for float and double
  FLOATING_POINT_DEC to NOT_FIXED_DEC
- When sending definition for a float/decimal field without decimals
  to the client as part of a result set we convert NOT_FIXED_DEC to
  FLOATING_POINT_DECIMALS.
- variance() and std() has changed to limit the decimals to
  FLOATING_POINT_DECIMALS -1 to not get the double converted floating point.
  (This was to preserve compatiblity)
- FLOAT and DOUBLE still have 30 as max number of decimals.

Bugs fixed:

variance() printed more decimals than we support for double values.

New behaviour:
- Strings now have 38 decimals instead of 30 when converted to decimal
- CREATE ... SELECT with a decimal with > 30 decimals will create a column
  with a smaller range than before as we are trying to preserve the number of
  decimals.


Other changes
- We are now using the obsolete bit FIELDFLAG_LEFT_FULLSCREEN to specify
  decimals > 31
- NOT_FIXED_DEC is now declared in one place
- For clients, NOT_FIXED_DEC is always 31 (to ensure compatibility).
  On the server NOT_FIXED_DEC is DECIMAL_NOT_SPECIFIED (39)
- AUTO_SEC_PART_DIGITS is taken from DECIMAL_NOT_SPECIFIED
- DOUBLE conversion functions are now using DECIMAL_NOT_SPECIFIED instead of
  NOT_FIXED_DEC
2016-06-22 22:04:55 +03:00
unknown
f9b3cc11bc MDEV-5819: MySQL Bug #13500371 63704: CONVERSION OF '1.' TO A NUMBER GIVES ERROR 1265 (WARN_DATA_TRUNCATED)
Fix by MySQL ported
2014-03-14 09:31:16 +02:00
Michael Widenius
068c61978e Temporary commit of 10.0-merge 2013-03-26 00:03:13 +02:00
Sergei Golubchik
20e706689d mysql-5.5.22 merge
mysql-test/suite/innodb/t/group_commit_crash.test:
  remove autoincrement to avoid rbr being used for insert ... select
mysql-test/suite/innodb/t/group_commit_crash_no_optimize_thread.test:
  remove autoincrement to avoid rbr being used for insert ... select
mysys/my_addr_resolve.c:
  a pointer to a buffer is returned to the caller -> the buffer cannot be on the stack
mysys/stacktrace.c:
  my_vsnprintf() is ok here, in 5.5
2012-03-28 01:04:46 +02:00
Sergei Golubchik
4933d21e5d merge with mysql-5.5.21 2012-03-09 08:06:59 +01:00
MySQL Build Team
7a35cb9150 Updated/added copyright headers 2012-02-16 10:48:16 +01:00
Tor Didriksen
4172d5e9a9 Bug#13359121 LARGE NUMBERS, /STRINGS/DTOA.C:662
Bug#12985021 SIMPLE QUERY WITH DECIMAL NUMBERS TAKE AN

When parsing the fractional part of a string which
is to be converted to double, we can stop after a few digits:
the extra digits will not contribute to the actual result anyways.


mysql-test/r/func_str.result:
  New tests.
mysql-test/t/func_str.test:
  New tests.
strings/dtoa.c:
  The problem was s2b() multiplying and adding hundreds-of-thousands
  of ever smaller fractions.
2012-01-25 16:11:03 +01:00
Michael Widenius
e6f5fc1c02 Fixed lp:909051 Options --debug and --disable-debug are known but ambiguous in RelWithDebInfo build
Fixed memory leak printing when doing 'mysqld --version', 'mysqld --debug --help' and 'mysqld --debug --help --verbose'


mysys/my_init.c:
  Moved checking if we should call DBUG_END() before my_thread_end() as otherwise we will not free DBUG variables and files.
mysys/thr_lock.c:
  Fixed compiler warning
sql/mysqld.cc:
  Fixed memory leaks when using mysqld --help and mysqld --version
  Added --debug as an option that works for all builds. For non debug builds we now get a warning.
strings/dtoa.c:
  Fixed valgrind warning (c could contain data outside of the given string)
2011-12-27 20:55:21 +02:00
Sergei Golubchik
0e007344ea mysql-5.5.18 merge 2011-11-03 19:17:05 +01:00
Sergei Golubchik
76f0b94bb0 merge with 5.3
sql/sql_insert.cc:
  CREATE ... IF NOT EXISTS may do nothing, but
  it is still not a failure. don't forget to my_ok it.
  ******
  CREATE ... IF NOT EXISTS may do nothing, but
  it is still not a failure. don't forget to my_ok it.
sql/sql_table.cc:
  small cleanup
  ******
  small cleanup
2011-10-19 21:45:18 +02:00
Tor Didriksen
f9b064a406 Bug#12985030 SIMPLE QUERY WITH DECIMAL NUMBERS LEAKS MEMORY
Extra fix: 'if (p5 < p5_a + P5A_MAX)' is not portable.
p5 starts out pointing to a static array, then may point
to a buffer on the stack, then may point to malloc()ed memory.
2011-09-21 13:46:49 +02:00
Tor Didriksen
dbcdad7d4a Bug#12985030 SIMPLE QUERY WITH DECIMAL NUMBERS LEAKS MEMORY
mysql-test/r/func_str.result:
  New test cases.
mysql-test/t/func_str.test:
  New test cases.
strings/dtoa.c:
  Increasing the buffer size slightly made some queries pass without leaks.
  Adding Bfree(p51, alloc) fixed the remaining leaks.
2011-09-20 10:59:48 +02:00
Kent Boortz
02e07e3b51 Updated/added copyright headers 2011-06-30 17:46:53 +02:00
Alexander Barkov
dfb7930b33 Merging Copyright update from 5.1 2011-01-19 16:31:17 +03:00
Alexey Kopytov
3e1a792c9b Bug #45882: dtoa.c might not work with gcc 4.4.0
- Ported relevant changes from the upstream version to not
break strict-aliasing rules and to fix compiler warnings and
and infinite loops caused by that issue.

- Fixed compilation with Honor_FLT_ROUNDS defined.

- Fixed an unused variable warning.
2010-06-01 21:37:45 +04:00
Alexey Kopytov
2d007e2aed Reconciling different file ids for dtoa.c in trunk and 6.0-codebase. 2010-04-11 10:52:42 +04:00
Alexey Kopytov
7dfa66cd30 Reconciling different file ids for dtoa.c in trunk and 6.0-codebase. 2010-04-11 10:48:58 +04:00
Alexey Kopytov
ee13669126 Bug #52165: Assertion failed: file .\dtoa.c, line 465
The failing assertion was written with the assumption that a NULL
string can never be passed to my_strtod(). However, an empty string
may be passed under some circumstances by passing str == NULL and
*end == NULL.

Fixed the assertion to take the above case into account.

mysql-test/r/func_misc.result:
  Added a test case for bug #52165.
mysql-test/t/func_misc.test:
  Added a test case for bug #52165.
strings/dtoa.c:
  Fixed the assertion in my_strtod() to take the case of 'str == NULL
  && *end == NULL' into account.
2010-04-07 13:59:02 +04:00
Alexey Kopytov
12f364ece7 Backport of WL #2934: Make/find library for doing float/double
to string conversions and vice versa" 
Initial import of the dtoa.c code and custom wrappers around it 
to allow its usage from the server code. 
 
Conversion of FLOAT/DOUBLE values to DECIMAL ones or strings 
and vice versa has been significantly reworked. As the new 
algoritms are more precise than the older ones, results of such 
conversions may not always match those obtained from older 
server versions. This in turn may break compatibility for some 
applications. 
 
This patch also fixes the following bugs: 
- bug #12860 "Difference in zero padding of exponent between 
Unix and Windows" 
- bug #21497 "DOUBLE truncated to unusable value" 
- bug #26788 "mysqld (debug) aborts when inserting specific 
numbers into char fields" 
- bug #24541 "Data truncated..." on decimal type columns 
without any good reason"
2009-12-22 19:23:13 +03:00
unknown
0411659765 WL #2934 "Make/find library for doing float/double to string conversions
and vice versa"
Initial import of the dtoa.c code and custom wrappers around it to allow
its usage from the server code.

Conversion of FLOAT/DOUBLE values to DECIMAL ones or strings and vice
versa has been significantly reworked. As the new algoritms are more
precise than the older ones, results of such conversions may not always
match those obtained from older server versions. This in turn may break
compatibility for some applications.

This patch also fixes the following bugs:
- bug #12860 "Difference in zero padding of exponent between Unix and
Windows"
- bug #21497 "DOUBLE truncated to unusable value"
- bug #26788 "mysqld (debug) aborts when inserting specific numbers into
char fields"
- bug #24541 "Data truncated..." on decimal type columns without any
good reason"


BitKeeper/deleted/.del-strtod.c:
  Rename: strings/strtod.c -> BitKeeper/deleted/.del-strtod.c
client/Makefile.am:
  Added dtoa.c
client/sql_string.cc:
  Replaced sprintf() with a new wrapper around dtoa()
include/m_string.h:
  Added declarations for the new double to/from string conversion 
  functions.
libmysql/Makefile.shared:
  Removed strtod.c, added dtoa.c
libmysql/libmysql.c:
  Replaced sprintf() with my_gcvt(). We must use the same conversion
  method in both server and client lib.
mysql-test/r/archive_gis.result:
  Fixed tests to take additional precision from dtoa() into account.
mysql-test/r/cast.result:
  Fixed tests to take the formatting changes into account.
mysql-test/r/func_group.result:
  Fixed tests to take additional precision from dtoa() into account.
mysql-test/r/func_math.result:
  Fixed tests to take additional precision from dtoa() and formatting
  changes into account.
mysql-test/r/func_str.result:
  Fixed tests to take additional precision from dtoa() and formatting
  changes into account.
mysql-test/r/gis.result:
  Fixed tests to take additional precision from dtoa() into account.
mysql-test/r/innodb_gis.result:
  Fixed tests to take additional precision from dtoa() into account.
mysql-test/r/insert.result:
  Fixed tests to take additional precision from dtoa() into account.
mysql-test/r/mysqldump.result:
  No need for result substitution since we do not rely on system behavior
  anymore.
mysql-test/r/ndb_gis.result:
  Fixed tests to take additional precision from dtoa() into account.
mysql-test/r/parser.result:
  Fixed tests to take additional precision from dtoa() into account.
mysql-test/r/ps_2myisam.result:
  Fixed tests to take additional precision from dtoa() and formatting
  changes into account.
mysql-test/r/ps_3innodb.result:
  Fixed tests to take additional precision from dtoa() and formatting
  changes into account.
mysql-test/r/ps_4heap.result:
  Fixed tests to take additional precision from dtoa() and formatting
  changes into account.
mysql-test/r/ps_5merge.result:
  Fixed tests to take additional precision from dtoa() and formatting
  changes into account.
mysql-test/r/ps_7ndb.result:
  Fixed tests to take additional precision from dtoa() and formatting
  changes into account.
mysql-test/r/select.result:
  Fixed tests to take additional precision from dtoa() into account.
mysql-test/r/sp.result:
  Fixed tests to take additional precision from dtoa() into account.
  Decimal 2.7182818284590452354 is now converted to the double value of
  2.718281828459045, not 2.718281828459. Thus we get additional precision
  from the subsequent calculations.
mysql-test/r/strict.result:
  Fixed tests to take additional precision from dtoa() and formatting
  changes into account.
mysql-test/r/type_decimal.result:
  Added a test case for bug #24541.
mysql-test/r/type_float.result:
  Fixed tests to take additional precision from dtoa() and formatting
  changes into account.
  Added test cases for bugs #12860, #21497 and #26788.
mysql-test/r/type_newdecimal.result:
  Fixed tests to take additional precision from dtoa() and formatting
  changes into account.
mysql-test/r/variables.result:
  Fixed tests to take the formatting changes into account.
mysql-test/r/view.result:
  Fixed tests to take additional precision from dtoa() into account.
mysql-test/t/cast.test:
  No need to replace the results for Windows anymore.
mysql-test/t/insert.test:
  Added test cases from bug #26788.
mysql-test/t/mysqldump.test:
  Fixed tests to take additional precision from dtoa() into account.
  No need for results substitution because we do not rely on system
  behavior anymore.
mysql-test/t/type_decimal.test:
  Added a test case for bug #24541.
mysql-test/t/type_float.test:
  Added test cases for bugs #12860, #21497 and #26788.
mysql-test/t/type_newdecimal.test:
  Removed replace_result which is pointless with our own floating point
  conversion library.
  Added a reference for WL#3977.
sql/field.cc:
  Replaced the field.cc's own constant for the maximum double->string 
  conversion buffer with the one defined in m_string.h
  Replaced double->string conversion code with the new wrappers around
  dtoa().
  Fixed a bug in Field_real::truncate() which led to incorrect results
  when +-Infinity was passed as an input number.
  Fixed Field_blob::store(double) to use NOT_FIXED_DEC instead of 2 as
  precision, so that my_gcvt() is now used for conversion.
sql/field.h:
  Moved NOT_FIXED_DEC to m_string.h because we now use this constant in
  floating point <-> string conversion routines.
sql/item.cc:
  If a result of a numeric functions is stored in a string field, follow
  the same rules as in Field_str::store(double), i.e. take the field width
  into account.
sql/log_event.cc:
  Replaced sprintf() with my_gcvt().
sql/mysql_priv.h:
  Moved log_10[] from strtod.c to mysqld.c, because we don't need it in
  libmystrings anymore.
sql/mysqld.cc:
  Moved log_10[] from strtod.c to mysqld.c, because we don't need it in
  libmystrings anymore.
sql/sql_show.cc:
  Replaced sprintf() with my_fcvt().
sql/sql_string.cc:
  Replace the double->string conversion code with the new wrappers around
  dtoa().
sql/unireg.h:
  Moved FLOATING_POINT_BUFFER from unireg.h to m_string.h so it can be
  used in libmystrings.
strings/Makefile.am:
  Removed strtod.c, added dtoa.c
strings/decimal.c:
  Replaced sprintf() with my_gcvt().
  Changed double2decimal() to print the digits to a string buffer, then
  use my_strtod().
strings/dtoa.c:
  Initial import of the dtoa code and custom wrappers around it to allow
  its usage from the server code.
2007-12-07 19:56:17 +03:00