summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS2
-rw-r--r--ext/gmp/gmp.c16
-rw-r--r--ext/gmp/tests/bug50175.phpt18
3 files changed, 27 insertions, 9 deletions
diff --git a/NEWS b/NEWS
index 1034a5d93f..f78969c233 100644
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,8 @@ PHP NEWS
- GMP:
. Fixed bug #67917 (Using GMP objects with overloaded operators can cause
memory exhaustion). (Nikita)
+ . Fixed bug #50175 (gmp_init() results 0 on given base and number starting
+ with 0x or 0b). (Nikita)
. Implemented gmp_import() and gmp_export(). (Leigh, Nikita)
- MySQLi:
diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c
index bf0f4f3fc7..619f1c39c3 100644
--- a/ext/gmp/gmp.c
+++ b/ext/gmp/gmp.c
@@ -773,15 +773,13 @@ static int convert_to_gmp(mpz_t gmpnumber, zval *val, int base TSRMLS_DC)
int skip_lead = 0;
int ret;
- if (Z_STRLEN_P(val) > 2) {
- if (numstr[0] == '0') {
- if (numstr[1] == 'x' || numstr[1] == 'X') {
- base = 16;
- skip_lead = 1;
- } else if (base != 16 && (numstr[1] == 'b' || numstr[1] == 'B')) {
- base = 2;
- skip_lead = 1;
- }
+ if (Z_STRLEN_P(val) > 2 && numstr[0] == '0') {
+ if ((base == 0 || base == 16) && (numstr[1] == 'x' || numstr[1] == 'X')) {
+ base = 16;
+ skip_lead = 1;
+ } else if ((base == 0 || base == 2) && (numstr[1] == 'b' || numstr[1] == 'B')) {
+ base = 2;
+ skip_lead = 1;
}
}
diff --git a/ext/gmp/tests/bug50175.phpt b/ext/gmp/tests/bug50175.phpt
new file mode 100644
index 0000000000..0998e029c3
--- /dev/null
+++ b/ext/gmp/tests/bug50175.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Bug #50175: gmp_init() results 0 on given base and number starting with 0x or 0b
+--FILE--
+<?php
+
+var_dump(gmp_init('0bcd', 16));
+var_dump(gmp_init('0xyz', 36));
+
+?>
+--EXPECTF--
+object(GMP)#%d (1) {
+ ["num"]=>
+ string(4) "3021"
+}
+object(GMP)#%d (1) {
+ ["num"]=>
+ string(5) "44027"
+}