Patch mysql_insert_id_convert_to_uint64_t for PDO MySQL Bug #80908
Patch version 2021-03-26 07:10 UTC
Return to Bug #80908 |
Download this patch
Patch Revisions:
Developer: atlanticfeng@icloud.com
diff --git a/ext/pdo/pdo.c b/ext/pdo/pdo.c
index 1120f9a326..39477ac2d0 100644
--- a/ext/pdo/pdo.c
+++ b/ext/pdo/pdo.c
@@ -281,6 +281,39 @@ PDO_API zend_string *php_pdo_int64_to_str(int64_t i64) /* {{{ */
}
/* }}} */
+PDO_API zend_string *php_pdo_uint64_to_str(uint64_t i64) /* {{{ */
+{
+ char buffer[65];
+ char outbuf[65] = "";
+ register char *p;
+ zend_long long_val;
+ char *dst = outbuf;
+
+ if (i64 == 0) {
+ return ZSTR_CHAR('0');
+ }
+
+ p = &buffer[sizeof(buffer)-1];
+ *p = '\0';
+
+ while ((uint64_t)i64 > (uint64_t)ZEND_LONG_MAX) {
+ uint64_t quo = (uint64_t)i64 / (unsigned int)10;
+ unsigned int rem = (unsigned int)(i64 - quo*10U);
+ *--p = digit_vec[rem];
+ i64 = (int64_t)quo;
+ }
+ long_val = (zend_long)i64;
+ while (long_val != 0) {
+ zend_long quo = long_val / 10;
+ *--p = digit_vec[(unsigned int)(long_val - quo * 10)];
+ long_val = quo;
+ }
+ while ((*dst++ = *p++) != 0)
+ ;
+ *dst = '\0';
+ return zend_string_init(outbuf, strlen(outbuf), 0);
+}
+
/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(pdo)
{
diff --git a/ext/pdo/php_pdo_driver.h b/ext/pdo/php_pdo_driver.h
index c1a01b3400..d4186fa541 100644
--- a/ext/pdo/php_pdo_driver.h
+++ b/ext/pdo/php_pdo_driver.h
@@ -27,6 +27,7 @@ typedef struct _pdo_row_t pdo_row_t;
struct pdo_bound_param_data;
PDO_API zend_string *php_pdo_int64_to_str(int64_t i64);
+PDO_API zend_string *php_pdo_uint64_to_str(uint64_t ui64);
#ifndef TRUE
# define TRUE 1
diff --git a/ext/pdo_mysql/mysql_driver.c b/ext/pdo_mysql/mysql_driver.c
index 7bc0cbcf0a..ba2dd318e9 100644
--- a/ext/pdo_mysql/mysql_driver.c
+++ b/ext/pdo_mysql/mysql_driver.c
@@ -289,7 +289,7 @@ static zend_string *pdo_mysql_last_insert_id(pdo_dbh_t *dbh, const zend_string *
{
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
PDO_DBG_ENTER("pdo_mysql_last_insert_id");
- PDO_DBG_RETURN(php_pdo_int64_to_str(mysql_insert_id(H->server)));
+ PDO_DBG_RETURN(php_pdo_uint64_to_str(mysql_insert_id(H->server)));
}
/* }}} */
|