php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32773 binary GMP functions returns unexpected value, when second parameter is int(0)
Submitted: 2005-04-19 22:32 UTC Modified: 2005-04-25 14:19 UTC
From: valyala at gmail dot com Assigned: stas (profile)
Status: Closed Package: Math related
PHP Version: 5.0.4 OS: unix
Private report: No CVE-ID: None
 [2005-04-19 22:32 UTC] valyala at gmail dot com
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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-21 13:15 UTC] tony2001@php.net
Assigning to the maintainer.
 [2005-04-25 14:19 UTC] stas@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 23:01:26 2024 UTC