[OpenAFS] Strange access problems on one client
Hans-Werner Paulsen
hans@MPA-Garching.MPG.DE
Thu, 11 Oct 2007 15:33:54 +0200
On Sun, Oct 07, 2007 at 01:15:00PM -0400, Marc Dionne wrote:
> Anyone care to test out the attached patch for src/dir/dir.c
>=20
> The hashing code in the DirHash() function relies on integer overflow t=
o=20
> make the hval value turn into a negative value. gcc 4.2 assumes that=20
> this value can never go negative and optimizes out the (hval < 0) test.
>=20
> Marc
>=20
> diff -u -r1.24 dir.c
> --- src/dir/dir.c 13 Oct 2005 15:12:12 -0000 1.24
> +++ src/dir/dir.c 7 Oct 2007 17:10:37 -0000
> @@ -478,8 +478,9 @@
> {
> /* Hash a string to a number between 0 and NHASHENT. */
> register unsigned char tc;
> - register int hval;
> + unsigned long hval;
> register int tval;
> +
> hval =3D 0;
> while ((tc =3D (*string++))) {
> hval *=3D 173;
> @@ -488,7 +489,7 @@
> tval =3D hval & (NHASHENT - 1);
> if (tval =3D=3D 0)
> return tval;
> - else if (hval < 0)
> + else if (hval >=3D 1<<31)
> tval =3D NHASHENT - tval;
> return tval;
> }
this patch is fine for architectures where the size of "unsigned long"
is 4 bytes. But on the x86_64 architecture this will not work, because
the size is 8 bytes. One can use "unsigned int".
HW
--=20
Hans-Werner Paulsen hans@MPA-Garching.MPG.DE
MPI f=FCr Astrophysik Tel 089-30000-2602
Karl-Schwarzschild-Str. 1 Fax 089-30000-2235=09
D-85741 Garching