diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2020-08-10 17:57:14 +0300 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2020-08-10 17:57:14 +0300 |
commit | 3b6dadb5ebedab71bf1870579745ff3cd05e498a (patch) | |
tree | 045f7347d2dde8ca4f7cddce0b91b7625cb9cf13 /strings/decimal.c | |
parent | 0460d42b949b1dd90117808919d7cc97b8ab16ae (diff) | |
parent | 7f67ef14852afebf90aaafdfc7295acbf0ad340f (diff) | |
download | mariadb-git-3b6dadb5ebedab71bf1870579745ff3cd05e498a.tar.gz |
Merge 10.1 into 10.2
Diffstat (limited to 'strings/decimal.c')
-rw-r--r-- | strings/decimal.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/strings/decimal.c b/strings/decimal.c index 21af3dc8882..2dd7c960a3e 100644 --- a/strings/decimal.c +++ b/strings/decimal.c @@ -812,6 +812,24 @@ internal_str2dec(const char *from, decimal_t *to, char **end, my_bool fixed) while (s < end_of_string && my_isdigit(&my_charset_latin1, *s)) s++; intg= (int) (s-s1); + /* + If the integer part is long enough and it has multiple leading zeros, + let's trim them, so this expression can return 1 without overflowing: + CAST(CONCAT(REPEAT('0',90),'1') AS DECIMAL(10)) + */ + if (intg > DIG_PER_DEC1 && s1[0] == '0' && s1[1] == '0') + { + /* + Keep at least one digit, to avoid an empty string. + So we trim '0000' to '0' rather than to ''. + Otherwise the below code (converting digits to to->buf) + would fail on a fatal error. + */ + const char *iend= s - 1; + for ( ; s1 < iend && *s1 == '0'; s1++) + { } + intg= (int) (s-s1); + } if (s < end_of_string && *s=='.') { endp= s+1; |