From b19a79d48986455711687ae693deb3ebca026edc Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Tue, 29 Mar 2022 13:25:59 +0200 Subject: [PATCH 1/2] Fix GH-8267: MySQLi uses unsupported format specifier on Windows Instead of using the unsupported `%I64u` and `%I64d` format specifiers on Windows, we use the portable `PRIu64` and `PRId64` specifiers. The `L64()` macro and the `my_longlong` typedef should be adapted as well, as the `i64` literal suffix is still supported by MSVC, but using `LL` or `ll` is recommended[1], and the standard `int64_t` is available there anyway. This is not urgent, though. [1] --- ext/mysqli/php_mysqli_structs.h | 11 +++++------ ext/mysqli/tests/gh8267.phpt | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 ext/mysqli/tests/gh8267.phpt diff --git a/ext/mysqli/php_mysqli_structs.h b/ext/mysqli/php_mysqli_structs.h index 16ed9ddefce5c..eb74a35697a04 100644 --- a/ext/mysqli/php_mysqli_structs.h +++ b/ext/mysqli/php_mysqli_structs.h @@ -134,8 +134,6 @@ typedef struct { #ifdef PHP_WIN32 #define PHP_MYSQLI_API __declspec(dllexport) -#define MYSQLI_LLU_SPEC "%I64u" -#define MYSQLI_LL_SPEC "%I64d" #ifndef L64 #define L64(x) x##i64 #endif @@ -146,16 +144,17 @@ typedef __int64 my_longlong; # else # define PHP_MYSQLI_API # endif -/* we need this for PRIu64 and PRId64 */ -#include -#define MYSQLI_LLU_SPEC "%" PRIu64 -#define MYSQLI_LL_SPEC "%" PRId64 #ifndef L64 #define L64(x) x##LL #endif typedef int64_t my_longlong; #endif +/* we need this for PRIu64 and PRId64 */ +#include +#define MYSQLI_LLU_SPEC "%" PRIu64 +#define MYSQLI_LL_SPEC "%" PRId64 + #ifdef ZTS #include "TSRM.h" #endif diff --git a/ext/mysqli/tests/gh8267.phpt b/ext/mysqli/tests/gh8267.phpt new file mode 100644 index 0000000000000..cdd9478c18c8b --- /dev/null +++ b/ext/mysqli/tests/gh8267.phpt @@ -0,0 +1,23 @@ +--TEST-- +Bug GH-8267 (MySQLi uses unsupported format specifier on Windows) +--SKIPIF-- + +--FILE-- +query("DROP TABLE IF EXISTS foo"); +$mysqli->query("CREATE TABLE foo (id BIGINT UNSIGNED AUTO_INCREMENT, PRIMARY KEY (id))"); +$mysqli->query("INSERT INTO foo VALUES (9223372036854775807)"); +var_dump($mysqli->insert_id); +$mysqli->query("INSERT INTO foo VALUES (0)"); +var_dump($mysqli->insert_id); +?> +--EXPECT-- +string(19) "9223372036854775807" +string(19) "9223372036854775808" From 8433ccb508af9f52d3d1a7af74fd712d337cbd4e Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Tue, 29 Mar 2022 13:53:15 +0200 Subject: [PATCH 2/2] fix test case --- ext/mysqli/tests/gh8267.phpt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ext/mysqli/tests/gh8267.phpt b/ext/mysqli/tests/gh8267.phpt index cdd9478c18c8b..204bfbb79caf9 100644 --- a/ext/mysqli/tests/gh8267.phpt +++ b/ext/mysqli/tests/gh8267.phpt @@ -9,8 +9,7 @@ require_once("skipifconnectfailure.inc"); query("DROP TABLE IF EXISTS foo"); $mysqli->query("CREATE TABLE foo (id BIGINT UNSIGNED AUTO_INCREMENT, PRIMARY KEY (id))"); $mysqli->query("INSERT INTO foo VALUES (9223372036854775807)");