|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47422 modulus operator returns incorrect results on 64 bit linux
Submitted: 2009-02-17 12:36 UTC Modified: 2009-02-17 14:22 UTC
From: d_kelsey at uk dot ibm dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.2CVS-2009-02-17 (CVS) OS: Linux 64Bit
Private report: No CVE-ID: None
 [2009-02-17 12:36 UTC] d_kelsey at uk dot ibm dot com
on a 64bit system the following 
should return 1, but returns 0. 
The problem is in the 
ZEND_API int mod_function(...) in zend_operators.c

A call is made to abs which expects a 32bit int and returns a 32bit int, but 4294967295 is > 32 bits in size so the abs call returns an incorrect value.

A proposed fix is to change the line
"if (abs(op2->value.lval) == 1) {"
"if (op2->value.lval == 1 || op2->value.lval == -1) {"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-17 14:22 UTC]
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
Thank you for the report, and for helping us make PHP better.

Thanks. Actually, just -1 needs to be checked there anyway, since only when doing LONG_MIN % -1 (in PHP, "(-PHP_INT_MAX - 1) % -1;") would there be a crash/error (which that's there to catch of course).
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Jan 16 05:01:25 2019 UTC