[PATCH] cpukit/libmisc: Cast getpid() before shifting

Kinsey Moore kinsey.moore at oarcorp.com
Tue Jan 16 23:52:49 UTC 2024


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);
-- 
2.39.2



More information about the devel mailing list