#32773 [NEW]: binary GMP functions returns unexpected value, when second parameter is int(0)
| From: | valyala at gmail dot com | Date: | Tue, 19 Apr 2005 20:32:26 +0000 |
| Subject: | #32773 [NEW]: binary GMP functions returns unexpected value, when second parameter is int(0) | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-77928@lists.php.net to get a copy of this message | ||
From: valyala at gmail dot com
Operating system: unix
PHP version: 5.0.4
PHP Bug Type: Math related
Bug description: binary GMP functions returns unexpected value, when second parameter is int(0)
Description:
------------
All binary functions from GMP extension return FALSE insted of expected
value, when zero is passed as second parameter.
I noticed the following piece of code in two places of ext/gmp/gmp.c file,
which purpose I couldn't understand:
if (!Z_LVAL_PP(b_arg)) {
RETURN_FALSE;
}
This code returns FALSE, when second parameter of binary GMP function
equals to zero.
I tried to delete this code from ext/gmp/gmp.c , and it seems that all
work nice after that.
Here is unified diff:
----------cut----------
--- gmp_old.c Tue Apr 19 23:18:06 2005
+++ gmp.c Tue Apr 19 23:18:28 2005
@@ -312,10 +312,6 @@
FETCH_GMP_ZVAL(gmpnum_b, b_arg);
}
- if (!Z_LVAL_PP(b_arg)) {
- RETURN_FALSE;
- }
-
INIT_GMP_NUM(gmpnum_result);
if (use_ui && gmp_ui_op) {
@@ -355,10 +351,6 @@
use_ui = 1;
} else {
FETCH_GMP_ZVAL(gmpnum_b, b_arg);
- }
-
- if (!Z_LVAL_PP(b_arg)) {
- RETURN_FALSE;
}
INIT_GMP_NUM(gmpnum_result1);
----------cut----------
Reproduce code:
---------------
<?
// all binary functions from GMP extension
// return FALSE insted of expected value,
// when zero is passed as second parameter.
echo '10 + 0 = ', gmp_strval(gmp_add(10, 0)), "\n";
// normal behaviour. Just convert zero into string
echo '10 + "0" = ', gmp_strval(gmp_add(10, '0')), "\n";
?>
Expected result:
----------------
10 + 0 = 10
10 + 0 = 10
Actual result:
--------------
10 + 0 = 0
10 + 0 = 10
--
Edit bug report at http://bugs.php.net/?id=32773&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=32773&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=32773&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=32773&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=32773&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=32773&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=32773&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=32773&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=32773&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=32773&r=support
Expected behavior: http://bugs.php.net/fix.php?id=32773&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=32773&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=32773&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=32773&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=32773&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=32773&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=32773&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=32773&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=32773&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=32773&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=32773&r=mysqlcfg