[rtems commit] cpukit/libmisc: Cast getpid() before shifting
Joel Sherrill
joel at rtems.org
Mon Jan 22 15:56:44 UTC 2024
Module: rtems
Branch: master
Commit: 07ee157e5e4ab567e1a926fcdd6eae4402b6bdd7
Changeset: http://git.rtems.org/rtems/commit/?id=07ee157e5e4ab567e1a926fcdd6eae4402b6bdd7
Author: Kinsey Moore <kinsey.moore at oarcorp.com>
Date: Tue Jan 16 17:49:29 2024 -0600
cpukit/libmisc: Cast getpid() before shifting
Cast getpid() before shifting to avoid truncation of upper bits before
the 64bit XOR occurs.
---
cpukit/libmisc/uuid/gen_uuid.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/cpukit/libmisc/uuid/gen_uuid.c b/cpukit/libmisc/uuid/gen_uuid.c
index 9b8dbeaa2e..5601c887c9 100644
--- a/cpukit/libmisc/uuid/gen_uuid.c
+++ b/cpukit/libmisc/uuid/gen_uuid.c
@@ -171,7 +171,12 @@ static int get_random_fd(void)
fcntl(fd, F_SETFD, i | FD_CLOEXEC);
}
#endif
+#ifdef __rtems__
+ srand((((time_t)getpid()) << ((sizeof(pid_t)*CHAR_BIT)>>1)) ^ getuid()
+ ^ tv.tv_sec ^ tv.tv_usec);
+#else
srand((getpid() << ((sizeof(pid_t)*CHAR_BIT)>>1)) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec);
+#endif
#ifdef DO_JRAND_MIX
jrand_seed[0] = getpid() ^ (tv.tv_sec & 0xFFFF);
jrand_seed[1] = getppid() ^ (tv.tv_usec & 0xFFFF);
More information about the vc
mailing list