From 8483ec41abdee0880de32fb30c9d37ec41e5db16 Mon Sep 17 00:00:00 2001 From: Christoph Niethammer Date: Thu, 2 Jul 2020 17:09:53 +0200 Subject: [PATCH] Fix shifting signed integer Shifting signed int will lead to undefined behavior in case of 1<<31 here Signed-off-by: Christoph Niethammer niethammer@hlrs.de --- opal/util/arch.c | 2 +- opal/util/net.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/opal/util/arch.c b/opal/util/arch.c index cf35b19c24e..8c18ed5305f 100644 --- a/opal/util/arch.c +++ b/opal/util/arch.c @@ -67,7 +67,7 @@ static inline int32_t opal_arch_ldisintel( void ) j = j-1; } } - return (pui[j] & (1 << i) ? 1 : 0); + return ((pui[j] & (1u << i)) ? 1 : 0); } static inline void opal_arch_setmask ( uint32_t *var, uint32_t mask) diff --git a/opal/util/net.c b/opal/util/net.c index 3f14d524b89..04d69b40677 100644 --- a/opal/util/net.c +++ b/opal/util/net.c @@ -202,7 +202,7 @@ opal_net_init(void) uint32_t opal_net_prefix2netmask(uint32_t prefixlen) { - return htonl (((1 << prefixlen) - 1) << (32 - prefixlen)); + return htonl (((1u << prefixlen) - 1u) << (32 - prefixlen)); }