X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=hv.h;h=c43fc57b2d0098291d6f4af4e69189725b3ff665;hb=0384d2fffd4e9480d75fd2afa397b45866ec8ac8;hp=6dc0a88f5b07a2120e76b69f4e3fae294d000994;hpb=e16e2ff836b177c52744755a35f12e818d01328b;p=p5sagit%2Fp5-mst-13.2.git diff --git a/hv.h b/hv.h index 6dc0a88..c43fc57 100644 --- a/hv.h +++ b/hv.h @@ -1,6 +1,7 @@ /* hv.h * - * Copyright (c) 1991-2002, Larry Wall + * Copyright (C) 1991, 1992, 1993, 1996, 1997, 1998, 1999, + * 2000, 2001, 2002, by Larry Wall and others * * You may distribute under the terms of either the GNU General Public * License or the Artistic License, as specified in the README file. @@ -47,14 +48,28 @@ struct xpvhv { }; /* hash a key */ -/* FYI: This is the "One-at-a-Time" algorithm by Bob Jenkins */ -/* from requirements by Colin Plumb. */ -/* (http://burtleburtle.net/bob/hash/doobs.html) */ +/* FYI: This is the "One-at-a-Time" algorithm by Bob Jenkins + * from requirements by Colin Plumb. + * (http://burtleburtle.net/bob/hash/doobs.html) */ +/* The use of a temporary pointer and the casting games + * is needed to serve the dual purposes of + * (a) the hashed data being interpreted as "unsigned char" (new since 5.8, + * a "char" can be either signed or signed, depending on the compiler) + * (b) catering for old code that uses a "char" + * The "hash seed" feature was added in Perl 5.8.1 to perturb the results + * to avoid "algorithmic complexity attacks". + */ +#if defined(USE_HASH_SEED) || defined(USE_HASH_SEED_EXPLICIT) +# define PERL_HASH_SEED PL_hash_seed +#else +# define PERL_HASH_SEED 0 +#endif #define PERL_HASH(hash,str,len) \ STMT_START { \ - register const char *s_PeRlHaSh = str; \ + register const char *s_PeRlHaSh_tmp = str; \ + register const unsigned char *s_PeRlHaSh = (const unsigned char *)s_PeRlHaSh_tmp; \ register I32 i_PeRlHaSh = len; \ - register U32 hash_PeRlHaSh = 0; \ + register U32 hash_PeRlHaSh = PERL_HASH_SEED; \ while (i_PeRlHaSh--) { \ hash_PeRlHaSh += *s_PeRlHaSh++; \ hash_PeRlHaSh += (hash_PeRlHaSh << 10); \