From: David Soria Parra Date: Tue, 24 Nov 2009 13:33:35 +0000 (+0000) Subject: Implement feature request #50283 (allow base in gmp_strval to use full range: 2 to... X-Git-Tag: php-5.2.12RC2~21 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0dc1918687032c08a00128cf26a21c30ae7d587e;p=php Implement feature request #50283 (allow base in gmp_strval to use full range: 2 to 62, and -2 to -36) --- 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-- + +--FILE-- + +--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: