From efc9f60dbf226a7bc9d9111e56ca969bc05724d1 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 7 Nov 2018 07:45:23 +0100 Subject: [PATCH] compilation failure on windows libmariadb\libmariadb\ma_stmt_codec.c(263): warning C4244: '*=': conversion from 'double' to 'unsigned long', possible loss of data generally avoid slow floating point pow() when all you need is to multiply an integer by a small power of 10. --- libmariadb/ma_stmt_codec.c | 5 ++++- unittest/libmariadb/ps_bugs.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libmariadb/ma_stmt_codec.c b/libmariadb/ma_stmt_codec.c index a91358df..bbb5743b 100644 --- a/libmariadb/ma_stmt_codec.c +++ b/libmariadb/ma_stmt_codec.c @@ -260,7 +260,10 @@ my_bool str_to_TIME(const char *str, size_t length, MYSQL_TIME *tm) goto error; /* conc-371 */ if (frac_len < 6) - tm->second_part*= pow(10, 6 - frac_len); + { + static ulong mul[]={1000000,100000,10000,1000,100,10}; + tm->second_part*= mul[frac_len]; + } } else { if (sscanf(start, "%d:%d:%d", &tm->hour, &tm->minute, &tm->second) < 3) diff --git a/unittest/libmariadb/ps_bugs.c b/unittest/libmariadb/ps_bugs.c index eb5a61ea..1a1dcdb9 100644 --- a/unittest/libmariadb/ps_bugs.c +++ b/unittest/libmariadb/ps_bugs.c @@ -4821,7 +4821,7 @@ static int test_conc_fraction(MYSQL *mysql) diag("second_part: %ld", tm.second_part); - expected= 9 * powl(10, (5 - i)); + expected= 9 * (unsigned int)powl(10, (5 - i)); FAIL_IF(tm.second_part != expected, "expected fractional part to be 900000");