Bug 145282 - Script Returns Incorrect Values
Summary: Script Returns Incorrect Values
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: php
Version: 3
Hardware: i386
OS: Linux
medium
high
Target Milestone: ---
Assignee: Joe Orton
QA Contact: David Lawrence
URL: http://www.milonic.com/bugreports/php...
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2005-01-16 22:09 UTC by Andy
Modified: 2007-11-30 22:10 UTC (History)
0 users

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2005-01-18 12:13:50 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Andy 2005-01-16 22:09:21 UTC
Description of problem:
PHP code is returning incorrect values but ONLY with Fedora (only tried FC3 so 
can't say if 1 and 2 are also affected)
Bascially, the code is not returning the correct values, it seems as though 
bit shifting is out of sync somehow.


Version-Release number of selected component (if applicable):
I'm using Kernel 2.6.10-1.741_FC3smp - occurs with PHP4.3.9, PHP4.3.10 and the 
latest PHP4.3.11-DEV - Compiled PHP from source and RPM's


How reproducible:
Run a small snippet of PHP found here: 
http://www.milonic.com/bugreports/php_fc3.php

Steps to Reproduce:
1.
2.
3.
  
  
Actual results:
251066875, 1541925888, -402039036


Expected results:
251066875,-1654377486,-1500734959 


Additional info:
This problem has also been reported to the PHP team 
http://bugs.php.net/bug.php?id=31569 
Thought i'd report it to you as we are not sure yet where the problem lies. 
The code used to generate the actual values can be executed almost identically 
in both PHP and JavaScript. 
Any OS other than FC3 will return the correct values. Have tried it with 
Redhat7, Redhat9 and FreeBSD 5.3 all of which are fine.

Comment 1 Joe Orton 2005-01-16 23:05:43 UTC
Are you getting the same erroneous results when compiling PHP from an upstream
CVS snapshot?

see also bug 143514 for different behaviour of "z = hex2dec(80000000)"
    

Comment 2 Andy 2005-01-18 07:44:02 UTC
Unfortunately yes I am getting the same results.

https://bugzilla.redhat.com/beta/show_bug.cgishow_bug.cgi?id=143514 is not a 
problem for me, I get the expected results with the latest version of PHP.

Narrowed the problem down to this:

<?
$b = 251066875;
$a = -3111919630;
echo $b ^= ($a<<10);
?>

     Fedora 3 echos: 251066875 (wrong)
All other OS's echo: 25768443 (correct)




Comment 3 Joe Orton 2005-01-18 12:13:50 UTC
As per upstream:

$a=-3111919630;
echo $b ^= ($a<<10);

1. -3111919630 cannot be represented in a 32-bit long, so it's stored in
a double
2. "$a << 10" is executed using (long) integer arithmetic, so $a is
converted to a long here
3. the Zend macro which converts double to long used to be miscompiled
by GCC, but this was fixed in the FC3 gcc.


Note You need to log in before you can comment on or make changes to this bug.