Hi all. I have some legacy C code (as a macro) that I am not allowed to change in any way, or replace.
This code (eventually) outputs out a digest (C) string based on the source string, performing an operation on the hash value for each character in the string.
#define DO_HASH(src, dest) { \
unsigned long hash = 1111; // Seed. You must NOT change this. \
char c, *srcPtr; \
int i; \
unsigned char hashedChar; \
\
srcPtr = src; \
c = *srcPtr++; \
while ( c) { \
hash = ((hash << 5) + hash) + c; \
c = *srcPtr++; \
} \
... // etc.
} //
Some years back, I had to implement it in PHP, as a function returning a digest string. The PHP function has to reproduce the C results identically.
function php_DO_HASH($srcStr)
{
$hash = 1111; // Seed. You must NOT change this.
$index = 0;
$c = $srcStr[$index];
while ($c) {
$hash = (($hash << 5) + $hash) + ord($c);
$index++;
$c = $srcStr[$index];
}
... // etc.
}
This has worked successfully for some years. However, in the last few days my server host upgraded to a new version of CentOS, but says they did not change the version of PHP. Since then, the two codes now generate different output.
Could anyone please advise as to what I'm doing wrong in the PHP version? Thanks.