]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/randutils: use explicit data types for bit ops
authorKarel Zak <kzak@redhat.com>
Tue, 28 Jan 2020 11:30:23 +0000 (12:30 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 28 Jan 2020 11:30:23 +0000 (12:30 +0100)
ASAN is pretty unhappy with getpid() << 16, it seems better to save
into unsigned int and than do the bit-op.

Addresses: https://github.com/karelzak/util-linux/issues/942
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/randutils.c

index e5deb74f18f3c80730afa74cc82462f8c76ced08..01a3d09036798a858550950ace425b52171241d0 100644 (file)
@@ -60,9 +60,12 @@ static void crank_random(void)
 {
        int i;
        struct timeval tv;
+       unsigned int n_pid, n_uid;
 
        gettimeofday(&tv, NULL);
-       srand((getpid() << 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec);
+       n_pid = getpid();
+       n_uid = getuid();
+       srand((n_pid << 16) ^ n_uid ^ tv.tv_sec ^ tv.tv_usec);
 
 #ifdef DO_JRAND_MIX
        ul_jrand_seed[0] = getpid() ^ (tv.tv_sec & 0xFFFF);