]> granicus.if.org Git - php/commitdiff
- revert last fix
authorPierre Joye <pajoye@php.net>
Thu, 9 Feb 2006 15:33:53 +0000 (15:33 +0000)
committerPierre Joye <pajoye@php.net>
Thu, 9 Feb 2006 15:33:53 +0000 (15:33 +0000)
- ensure that we are in 32bit
- do not try to compare the decimal values but hex, php does not have
  unsigned integer

ext/standard/crc32.c
ext/standard/tests/strings/bug36306.phpt

index 02bc54e623fd636dbc0a9fd47c2ab30904fc307b..774564a71591abdd2f1d3096e1a23aafa072dfd1 100644 (file)
 #include "basic_functions.h"
 #include "crc32.h"
 
-/* {{{ proto string crc32(string str)
-   Calculate the crc32 polynomial of a string */
 PHP_NAMED_FUNCTION(php_if_crc32)
 {
-       unsigned int crc = ~0;
        char *p;
        int len, nr;
-       
+       php_uint32 crcinit = 0;
+       register php_uint32 crc;
+
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &p, &nr) == FAILURE) {
                return;
        }
+       crc = crcinit^0xFFFFFFFF;
 
-       len = 0 ;
-       for (len += nr; nr--; ++p) {
-           CRC32(crc, *p);
+       for (len =+nr; nr--; ++p) {
+               crc = ((crc >> 8) & 0x00FFFFFF) ^ crc32tab[(crc ^ (*p)) & 0xFF ];
        }
-       RETVAL_LONG(~ (long) crc);
+       RETVAL_LONG(crc^0xFFFFFFFF);
 }
-/* }}} */
 
 /*
  * Local variables:
index a4a02dd65842f37034c522143255d4e03af05607..ff6279a2d34c374b576e19c59a07e3e509f7cc0c 100644 (file)
@@ -2,7 +2,14 @@
 Bug #36306 crc32() 64bit
 --FILE--
 <?php
-echo crc32("platform independant") . "\n";
+
+/* as an example how to write crc32 tests
+   PHP does not have uint values, you cannot
+   display crc32 like a signed integer.
+   Have to find some small strings to truely reproduce 
+   the problem, this example being not a problem
+*/
+echo dechex(crc32("platform independant")) . "\n";
 ?>
 --EXPECT--
--858128794
+ccd9fe66