* [PATCH] shared/util: Fix undefined behavior of left shift
@ 2020-06-03 17:56 Sonny Sasaka
2020-06-03 21:07 ` Luiz Augusto von Dentz
0 siblings, 1 reply; 2+ messages in thread
From: Sonny Sasaka @ 2020-06-03 17:56 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Sonny Sasaka
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] shared/util: Fix undefined behavior of left shift
2020-06-03 17:56 [PATCH] shared/util: Fix undefined behavior of left shift Sonny Sasaka
@ 2020-06-03 21:07 ` Luiz Augusto von Dentz
0 siblings, 0 replies; 2+ messages in thread
From: Luiz Augusto von Dentz @ 2020-06-03 21:07 UTC (permalink / raw)
To: Sonny Sasaka; +Cc: linux-bluetooth
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.
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-06-03 21:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-03 17:56 [PATCH] shared/util: Fix undefined behavior of left shift Sonny Sasaka
2020-06-03 21:07 ` Luiz Augusto von Dentz
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.