modulus operator returns incorrect results on 64 bit linux
| 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
Description:
------------
on a 64bit system the following
var_dump(1%4294967295);
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) {"
to
"if (op2->value.lval == 1 || op2->value.lval == -1) {"
Patches
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2009-02-17 14:22 UTC] mattwil@php.net