Skip to content

Commit 844a124

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #79596: MySQL FLOAT truncates to int some locales
2 parents f4c9f8b + d1cd489 commit 844a124

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ PHP NEWS
1111
- FFI:
1212
. Fixed bug #79571 (FFI: var_dumping unions may segfault). (cmb)
1313

14+
- MySQLnd:
15+
. Fixed bug #79596 (MySQL FLOAT truncates to int some locales). (cmb)
16+
1417
- Opcache:
1518
. Fixed bug #79588 (Boolean opcache settings ignore on/off values). (cmb)
1619

ext/mysqlnd/mysql_float_to_double.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
/*
3333
* Convert from a 4-byte float to a 8-byte decimal by first converting
34-
* the float to a string, and then the string to a double.
34+
* the float to a string (ignoring localization), and then the string to a double.
3535
* The decimals argument specifies the precision of the output. If decimals
3636
* is less than zero, then a gcvt(3) like logic is used with the significant
3737
* digits set to FLT_DIG i.e. 6.
@@ -42,7 +42,7 @@ static inline double mysql_float_to_double(float fp4, int decimals) {
4242
if (decimals < 0) {
4343
php_gcvt(fp4, FLT_DIG, '.', 'e', num_buf);
4444
} else {
45-
sprintf(num_buf, "%.*f", decimals, fp4);
45+
snprintf(num_buf, MAX_CHAR_BUF_LEN, "%.*F", decimals, fp4);
4646
}
4747

4848
return zend_strtod(num_buf, NULL);

ext/pdo_mysql/tests/bug79596.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Bug #79596 (MySQL FLOAT truncates to int some locales)
3+
--SKIPIF--
4+
<?php
5+
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc');
6+
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7+
MySQLPDOTest::skip();
8+
if (!setlocale(LC_ALL, 'de_DE', 'de-DE')) die('skip German locale not available');
9+
?>
10+
--FILE--
11+
<?php
12+
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
13+
14+
setlocale(LC_ALL, 'de_DE', 'de-DE');
15+
16+
$pdo = MySQLPDOTest::factory();
17+
$pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
18+
$pdo->query('CREATE TABLE bug79596 (broken FLOAT(2,1))');
19+
$pdo->query('INSERT INTO bug79596 VALUES(4.9)');
20+
var_dump($pdo->query('SELECT broken FROM bug79596')->fetchColumn(0));
21+
?>
22+
--CLEAN--
23+
<?php
24+
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
25+
26+
$pdo = MySQLPDOTest::factory();
27+
$pdo->exec("DROP TABLE IF EXISTS bug79596");
28+
?>
29+
--EXPECT--
30+
float(4,9)

0 commit comments

Comments
 (0)