From: Benjamin Kaduk Date: Sun, 3 Feb 2019 01:45:31 +0000 (-0600) Subject: rework afs_random() yet again X-Git-Tag: upstream/1.8.6_pre1^2~40 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=f5f44ca2efa3534e84a5311fec7a637ec7bf5d9b;p=packages%2Fo%2Fopenafs.git rework afs_random() yet again clang 7 notes that ~0 is signed and that left-shifting into the sign bit is undefined behvaior. Use a new construction to clear the low byte of tv_usec with only bitwise operations that are independent of the width of tv_usec and stay within the realm of C's defined behavior. Reviewed-on: https://gerrit.openafs.org/13474 Tested-by: BuildBot Reviewed-by: Cheyenne Wills Reviewed-by: Michael Meffie Reviewed-by: Benjamin Kaduk (cherry picked from commit f0a3d477d6109697645cfdcc17617b502349d91b) Change-Id: I4f0438c2fc8237968f41409ca23ac098839508fe Reviewed-on: https://gerrit.openafs.org/13743 Reviewed-by: Michael Meffie Reviewed-by: Andrew Deason Tested-by: BuildBot Reviewed-by: Stephan Wiesand --- diff --git a/src/afs/afs_server.c b/src/afs/afs_server.c index 79b4704ec..327c0c5b9 100644 --- a/src/afs/afs_server.c +++ b/src/afs/afs_server.c @@ -824,10 +824,12 @@ afs_random(void) osi_timeval_t t; osi_GetTime(&t); /* - * 0xfffffff0 was changed to (~0 << 4) since it works no matter how many - * bits are in a tv_usec + * Clear the low byte of tv_usec in a size-independent manner before adding + * in the rest of the state. */ - state = (t.tv_usec & (~0 << 4)) + (rxi_getaddr() & 0xff); + state = t.tv_usec; + state ^= (state & 0xff); + state += rxi_getaddr() & 0xff; state += (t.tv_sec & 0xff); for (i = 0; i < 30; i++) { ranstage(state);