php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #18816 results of ip2long and crc32 differ on different os/architectures
Submitted: 2002-08-08 16:08 UTC Modified: 2003-01-19 22:08 UTC
From: nohn@php.net Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4CVS-2002-08-08 OS: Linux, Tru64
Private report: No CVE-ID: None
 [2002-08-08 16:08 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-08-08 16:09 UTC] 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:23 UTC] 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 17:01 UTC] 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-10 06:59 UTC] yohgaki@php.net
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.

 [2003-01-19 22:08 UTC] pollita@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Nov 25 21:01:33 2024 UTC