[PATCH] shared/util: Fix undefined behavior of left shift

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When left-shifting 1, we should be explicit that it is an unsigned 1.
---
 src/shared/util.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/shared/util.c b/src/shared/util.c
index 330a0722a..3b976fa16 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -140,7 +140,7 @@ uint8_t util_get_uid(unsigned int *bitmap, uint8_t max)
 	if (!id || id > max)
 		return 0;
 
-	*bitmap |= 1 << (id - 1);
+	*bitmap |= 1u << (id - 1);
 
 	return id;
 }
@@ -151,7 +151,7 @@ void util_clear_uid(unsigned int *bitmap, uint8_t id)
 	if (!id)
 		return;
 
-	*bitmap &= ~(1 << (id - 1));
+	*bitmap &= ~(1u << (id - 1));
 }
 
 static const struct {
-- 
2.26.2




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux