summaryrefslogtreecommitdiff
path: root/ext/gmp
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
commit18f32db810f41fe9b8c2232779793631e336a5a3 (patch)
tree730b6d614ad31c678d2ea7a1d922d295542acdb2 /ext/gmp
parent2e35533fc67456b5542977aecf325dc06c9d69d7 (diff)
downloadphp-git-18f32db810f41fe9b8c2232779793631e336a5a3.tar.gz
Implement feature request #50283 (allow base in gmp_strval to use full range: 2 to 62, and -2 to -36)
Diffstat (limited to 'ext/gmp')
-rw-r--r--ext/gmp/gmp.c4
-rw-r--r--ext/gmp/tests/bug50283.phpt29
2 files changed, 31 insertions, 2 deletions
diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c
index d4d7e30c52..ee3751712c 100644
--- a/ext/gmp/gmp.c
+++ b/ext/gmp/gmp.c
@@ -796,14 +796,14 @@ ZEND_FUNCTION(gmp_strval)
return;
}
- 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: %ld", base);
RETURN_FALSE;
}
FETCH_GMP_ZVAL(gmpnum, gmpnumber_arg, temp_a);
- 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: