Message ID | 20200603175600.3006-1-sonnysasaka@chromium.org (mailing list archive) |
---|---|
State | Accepted |
Headers | show |
Series | shared/util: Fix undefined behavior of left shift | expand |
Hi Sonny, On Wed, Jun 3, 2020 at 10:58 AM Sonny Sasaka <sonnysasaka@chromium.org> wrote: > > 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 Applied, thanks.
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 {