summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Soria Parra <dsp@php.net>2009-11-24 13:33:35 +0000
committerDavid Soria Parra <dsp@php.net>2009-11-24 13:33:35 +0000
commit0dc1918687032c08a00128cf26a21c30ae7d587e (patch)
treece9bd0d320bceb7c24825651a55df415208a25a4
parent7a5348280e722338fe90195181770d4b4745f9b5 (diff)
downloadphp-git-0dc1918687032c08a00128cf26a21c30ae7d587e.tar.gz
Implement feature request #50283 (allow base in gmp_strval to use full range: 2 to 62, and -2 to -36)
-rw-r--r--NEWS2
-rw-r--r--ext/gmp/gmp.c4
-rw-r--r--ext/gmp/tests/bug50283.phpt29
3 files changed, 33 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index c8f18c8970..b60486c616 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,8 @@ PHP NEWS
- Fixed error_log() to be binary safe when using message_type 3. (Jani)
+- Implement feature request #50283 (allow base in gmp_strval to use full
+ range: 2 to 62, and -2 to -36). (David Soria Parra)
- Fixed bug #50282 (xmlrpc_encode_request() changes object into array in
calling function). (Felipe)
- Fixed bug #50219 (soap call Segmentation fault on a redirected url).
diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c
index 406862ebaa..075f67499f 100644
--- a/ext/gmp/gmp.c
+++ b/ext/gmp/gmp.c
@@ -817,12 +817,12 @@ ZEND_FUNCTION(gmp_strval)
break;
}
- if (base < 2 || base > 36) {
+ if ((base < 2 && base > -2) || base > 36 || base < -36) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad base for conversion: %d", base);
RETURN_FALSE;
}
- num_len = mpz_sizeinbase(*gmpnum, base);
+ num_len = mpz_sizeinbase(*gmpnum, abs(base));
out_string = emalloc(num_len+2);
if (mpz_sgn(*gmpnum) < 0) {
num_len++;
diff --git a/ext/gmp/tests/bug50283.phpt b/ext/gmp/tests/bug50283.phpt
new file mode 100644
index 0000000000..4842c00598
--- /dev/null
+++ b/ext/gmp/tests/bug50283.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Feature Request #50283 (allow base in gmp_strval to use full range: 2 to 62, and -2 to -36)
+--SKIPIF--
+<?php if (!extension_loaded("gmp")) print "skip"; ?>
+--FILE--
+<?php
+$a = gmp_init("0x41682179fbf5");
+printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,-36));
+printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,36));
+printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,-1));
+printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,1));
+printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,-37));
+printf("Decimal: %s, 36-based: %s\n", gmp_strval($a), gmp_strval($a,37));
+?>
+--EXPECTF--
+Decimal: 71915494046709, 36-based: PHPISCOOL
+Decimal: 71915494046709, 36-based: phpiscool
+
+Warning: gmp_strval(): Bad base for conversion: -1 in %s on line 5
+Decimal: 71915494046709, 36-based:
+
+Warning: gmp_strval(): Bad base for conversion: 1 in %s on line 6
+Decimal: 71915494046709, 36-based:
+
+Warning: gmp_strval(): Bad base for conversion: -37 in %s on line 7
+Decimal: 71915494046709, 36-based:
+
+Warning: gmp_strval(): Bad base for conversion: 37 in %s on line 8
+Decimal: 71915494046709, 36-based: