[PHP-BUG] Bug #51397 [NEW]: Math calculation bug

[email protected] ("emanuel dot dejanu at humaninfo dot ro")
Newsgroups php.bugs
Message-ID <[email protected]>
From:             
Operating system: FREEBSD & LINUX
PHP version:      5.2.13
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:Math calculation bug

Description:
------------

I have used the code from the test script on my development machine
(Windows Professional 7 32bit) with php 5.2.12 and is working correctly but
when I have deployed on my production machine that is FreeBSD 6.3 32bit
with the same php version 5.2.12 is giving wrong results (-2147483593). I
also run this on other production machine that is RedHat 5 32bit with php
5.2.6 and is also giving wrong results (-2147483593).

I can not test with php 5.2.13 on production machines (virtual hosting).
On windows is giving the correctly result (754303898) with PHP 5.2.12 and
PHP 5.3.1. I am running in 32bit platform on all machines.

-------------------------------------------------------------------

PHP_INT_SIZE: 4

System => FreeBSD somehost.com 6.3-RELEASE FreeBSD 6.3-RELEASE #6: Wed Oc
t 21 09:32:42 MDT 2009     root@fc:/usr/src/sys/i386/compile/VKERN i386
Build Date => Mar  3 2010 12:51:00
Configure Command =>  './configure'  '--with-layout=GNU'
'--with-config-file-sca
n-dir=/usr/local/etc/php' '--disable-all' '--enable-libxml'
'--with-libxml-dir=/
usr/local' '--enable-reflection' '--program-prefix=' '--enable-fastcgi'
'--with-
apxs2=/usr/local/sbin/apxs' '--with-regex=php' '--with-zend-vm=CALL'
'--prefix=/
usr/local' '--mandir=/usr/local/man' '--infodir=/usr/local/info/'
'--build=i386-
portbld-freebsd6.3'
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /usr/local/etc
Loaded Configuration File => /usr/local/etc/php.ini
Scan this dir for additional .ini files => /usr/local/etc/php
additional .ini files parsed => /usr/local/etc/php/extensions.ini

PHP API => 20041225
PHP Extension => 20060613
Zend Extension => 220060519
Debug Build => no



Test script:
---------------
function myhash($key) {
        $h = 5381;
        $l = strlen($key);
        for($i = 0; $i < $l; ++$i) {
            $h = (($h << 5) + $h) ^ ord($key[$i]);
        }
        return $h;
}
$h = myhash('CL6.1.7');
if ($h != 754303898)
        echo "bug\n";
echo $h . "\n";


Expected result:
----------------
754303898


Actual result:
--------------
bug
-2147483593

-- 
Edit bug report at http://bugs.php.net/bug.php?id=51397&edit=1
-- 
Try a snapshot (PHP 5.2):            http://bugs.php.net/fix.php?id=51397&r=trysnapshot52
Try a snapshot (PHP 5.3):            http://bugs.php.net/fix.php?id=51397&r=trysnapshot53
Try a snapshot (PHP 6.0):            http://bugs.php.net/fix.php?id=51397&r=trysnapshot60
Fixed in SVN:                        http://bugs.php.net/fix.php?id=51397&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=51397&r=needdocs
Fixed in release:                    http://bugs.php.net/fix.php?id=51397&r=alreadyfixed
Need backtrace:                      http://bugs.php.net/fix.php?id=51397&r=needtrace
Need Reproduce Script:               http://bugs.php.net/fix.php?id=51397&r=needscript
Try newer version:                   http://bugs.php.net/fix.php?id=51397&r=oldversion
Not developer issue:                 http://bugs.php.net/fix.php?id=51397&r=support
Expected behavior:                   http://bugs.php.net/fix.php?id=51397&r=notwrong
Not enough info:                     http://bugs.php.net/fix.php?id=51397&r=notenoughinfo
Submitted twice:                     http://bugs.php.net/fix.php?id=51397&r=submittedtwice
register_globals:                    http://bugs.php.net/fix.php?id=51397&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=51397&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=51397&r=dst
IIS Stability:                       http://bugs.php.net/fix.php?id=51397&r=isapi
Install GNU Sed:                     http://bugs.php.net/fix.php?id=51397&r=gnused
Floating point limitations:          http://bugs.php.net/fix.php?id=51397&r=float
No Zend Extensions:                  http://bugs.php.net/fix.php?id=51397&r=nozend
MySQL Configuration Error:           http://bugs.php.net/fix.php?id=51397&r=mysqlcfg
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.