Make locale archive hash function architecture-independent
Joseph S. Myers
joseph@codesourcery.com
Thu Sep 12 16:31:00 GMT 2013
On Thu, 12 Sep 2013, Andreas Schwab wrote:
> "Joseph S. Myers" <joseph@codesourcery.com> writes:
>
> > diff --git a/locale/hashval.h b/locale/hashval.h
> > index 737162f..c714ec6 100644
> > --- a/locale/hashval.h
> > +++ b/locale/hashval.h
> > @@ -37,7 +37,7 @@ compute_hashval (const void *key, size_t keylen)
> > while (cnt < keylen)
> > {
> > hval = (hval << 9) | (hval >> (sizeof hval * CHAR_BIT - 9));
> > - hval += (hashval_t) *(((char *) key) + cnt++);
> > + hval += (hashval_t) *(((unsigned char *) key) + cnt++);
>
> IMHO writing it like this is easier to parse:
>
> hval += (hashval_t) ((unsigned char *) key)[cnt++];
Here is a patch version using that form. This produces unchanged
localedef and shared library binaries (compared to a tree with the
previous version of this patch).
2013-09-12 Joseph Myers <joseph@codesourcery.com>
* locale/hashval.h (compute_hashval): Interpret bytes of key as
unsigned char.
diff --git a/locale/hashval.h b/locale/hashval.h
index 737162f..4282445 100644
--- a/locale/hashval.h
+++ b/locale/hashval.h
@@ -37,7 +37,7 @@ compute_hashval (const void *key, size_t keylen)
while (cnt < keylen)
{
hval = (hval << 9) | (hval >> (sizeof hval * CHAR_BIT - 9));
- hval += (hashval_t) *(((char *) key) + cnt++);
+ hval += (hashval_t) ((unsigned char *) key)[cnt++];
}
return hval != 0 ? hval : ~((hashval_t) 0);
}
--
Joseph S. Myers
joseph@codesourcery.com
More information about the Libc-alpha
mailing list