Skip to content

Commit

Permalink
CONC-371 fix for frac > 6
Browse files Browse the repository at this point in the history
  • Loading branch information
vuvova committed Nov 7, 2018
1 parent efc9f60 commit 6545b1d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion libmariadb/ma_stmt_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ my_bool str_to_TIME(const char *str, size_t length, MYSQL_TIME *tm)
if ((frac= strchr(start, '.'))) /* fractional seconds */
{
size_t frac_len= (begin + length) - (frac + 1);
if (sscanf(start, "%d:%d:%d.%ld", &tm->hour, &tm->minute,
if (sscanf(start, "%d:%d:%d.%6ld", &tm->hour, &tm->minute,
&tm->second,&tm->second_part) < 4)
goto error;
/* conc-371 */
Expand Down
8 changes: 5 additions & 3 deletions unittest/libmariadb/ps_bugs.c
Original file line number Diff line number Diff line change
Expand Up @@ -4792,11 +4792,12 @@ static int test_conc_fraction(MYSQL *mysql)
int i;
MYSQL_STMT *stmt= mysql_stmt_init(mysql);
int rc;
unsigned long frac= 0;

for (i=0; i < 6; i++)
for (i=0; i < 10; i++, frac=frac*10+i)
{
unsigned long expected= 0;
sprintf(query, "SELECT '2018-11-05 22:25:59.%0*d'", i + 1, 9);
sprintf(query, "SELECT '2018-11-05 22:25:59.%ld'", frac);

diag("%d: %s", i, query);

Expand All @@ -4821,8 +4822,9 @@ static int test_conc_fraction(MYSQL *mysql)

diag("second_part: %ld", tm.second_part);

expected= 9 * (unsigned int)powl(10, (5 - i));
expected= i > 6 ? 123456 : frac * (unsigned int)powl(10, (6 - i));

diag("tm.second_part=%ld expected=%ld", tm.second_part, expected);
FAIL_IF(tm.second_part != expected, "expected fractional part to be 900000");

}
Expand Down

0 comments on commit 6545b1d

Please sign in to comment.