[PATCH] fix an undefined behavior

Aleksander Morgado aleksander at aleksander.es
Wed Oct 28 14:35:04 PDT 2015


Hey!

On Wed, Oct 28, 2015 at 10:23 PM, Yunlian Jiang <yunlian at chromium.org> wrote:
> A shift has undefined behaviour if the mathematical result
> (lhs * 2^{rhs}) doesn't fit in the range of the resulting type.
> In other words, you can't left shift into the sign bit of a
> signed integer type.
> The error message is:
>
> mm-broadband-modem.c:3308:15: runtime error: left shift of 1 by 31
> places cannot be represented in type 'int'
> SUMMARY: AddressSanitizer: undefined-behavior mm-broadband-modem.c:3308:15 in
> ---

Thanks, pushed the patch you attached. Next time please either attach
the patch or use git send-email, not both things :) A bit confusing
because the email didn't apply cleanly while the attachment did.

Was that the only place for such an issue? We do bitshifts in quite
some other places as well.

>  src/mm-broadband-modem.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c
> index d2bfd91..8526646 100644
> --- a/src/mm-broadband-modem.c
> +++ b/src/mm-broadband-modem.c
> @@ -3315,7 +3315,7 @@ get_next_facility_lock_status
> (LoadEnabledFacilityLocksContext *ctx)
>      guint i;
>
>      for (i = ctx->current; i < sizeof (MMModem3gppFacility) * 8; i++) {
> -        guint32 facility = 1 << i;
> +        guint32 facility = 1u << i;
>
>          /* Found the next one to query! */
>          if (ctx->facilities & facility) {
> --
> 2.6.0.rc2.230.g3dd15c0



-- 
Aleksander
https://aleksander.es


More information about the ModemManager-devel mailing list