From 49874d2cff79a7cafadc0c88f28199c454e981ab Mon Sep 17 00:00:00 2001 From: Nick Brown Date: Wed, 12 Oct 2022 14:23:50 -0700 Subject: [PATCH] Avoid UB when bit shifting The 0 literal is a signed integer; bitshifting its (negative) complement is undefined behavior. PiperOrigin-RevId: 480717288 --- test/syscalls/linux/socket_ip_unbound.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/syscalls/linux/socket_ip_unbound.cc b/test/syscalls/linux/socket_ip_unbound.cc index d470a7206..cd8ecb655 100644 --- a/test/syscalls/linux/socket_ip_unbound.cc +++ b/test/syscalls/linux/socket_ip_unbound.cc @@ -284,7 +284,7 @@ TEST_P(IPUnboundSocketTest, SmallTOSOptionSize) { EXPECT_EQ(get_sz, expect_sz); // Account for partial copies by getsockopt, retrieve the lower // bits specified by get_sz, while comparing against expect_tos. - EXPECT_EQ(get & ~(~0 << (get_sz * 8)), expect_tos); + EXPECT_EQ(get & ~(~static_cast(0) << (get_sz * 8)), expect_tos); } }