#18816 [Opn]: results of ip2long and crc32 differ on different os/architectures

From: Date: Sat, 10 Aug 2002 11:00:00 +0000
Subject: #18816 [Opn]: results of ip2long and crc32 differ on different os/architectures
References: 1  Groups: php.bugs php.doc 
Request: Send a blank email to php-bugs+get-16425@lists.php.net to get a copy of this message
ID: 18816 Updated by: yohgaki@php.net Reported By: nohn@php.net Status: Open Bug Type: Documentation problem Operating System: Linux, Tru64 PHP Version: 4CVS-2002-08-08 New Comment: All functions that requrie unsigned int may be affected. BTW, PostgreSQL OID is free from this restriction, since I changed source to use string if value is larger than 2^31. So postgreSQL document can be left as is. Previous Comments: ------------------------------------------------------------------------ [2002-08-08 17:01:31] nohn@php.net Reopened this. This should definitly be documented! On ip2long documentation it is, on crc32 it is not. Which other functions are affected by this? ------------------------------------------------------------------------ [2002-08-08 16:23:55] iliaa@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php This is because you are using 2 different architectures, on X86 (AMD k6) ints are 32 bit, but on Compaq Tru64 (ALpha EV68) they are 64 bit. Since PHP uses signed ints you got a negative number on X86 where signed ints are limited to 2147483647 and your result is >3 billion. If you explicitly tell PHP to output an unsigned number it will work correctly. printf("%u", ip2long('192.168.0.1')); ----- 3232235521 Same logic applies to your crc, example. ------------------------------------------------------------------------ [2002-08-08 16:09:58] nohn@php.net Ahh... Please note that I may not be reachable in the next days for questions, but you may use http://www.testdrive.compaq.com/ to verify this ------------------------------------------------------------------------ [2002-08-08 16:08:45] nohn@php.net Following Script produces this output: $ip = "192.168.0.1"; echo("$ip\n"); echo(ip2long($ip)); ---- On Debian/i386 (AMD K6): 192.168.0.1 -1062731775 ---- On Compaq Tru64 (ALpha EV68): 192.168.0.1 3232235521 =========================================================================================================== Following Script produces this output: $text = "Der schnelle braune Fuchs springt über den blöden Hund."; echo "$text\n"; echo(crc32($text)); ---- On Debian/i386 (AMD K6): Der schnelle braune Fuchs springt über den blöden Hund. -2050320634 ---- On Compaq Tru64 (Alpha EV68): Der schnelle braune Fuchs springt über den blöden Hund. 1367081892 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=18816&edit=1

« previous php.bugs (#16425) next »