Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp688320ybg; Wed, 3 Jun 2020 10:56:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvjFdq1QfWPZBi+7VxDD/lrtWOsdextSQCWm9ChBIlvo6IRiIYWdYfvn02vkWDB0fLsbRp X-Received: by 2002:a17:906:dbda:: with SMTP id yc26mr452661ejb.82.1591207005570; Wed, 03 Jun 2020 10:56:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591207005; cv=none; d=google.com; s=arc-20160816; b=HzYOsb0MY+gxptRi5Ojaf4GXF9N71ZBjNP9P/UgEgelN75TYWsrSk+4YtQOKvOboyG J+YKDHHrvALC35nWMxbBWK41/suztTWkyXNzRpMg5LT4oi6BwbWuyuXsHkRuZC2wSCY+ r6R2E4jACb4sgWx91NOO4jT2Zn758WN3XFVr1BwUoEZvFxtJcrqg+uuIpKDNAxIIv2b+ ui/8Ms13pqjjYqu57NMZqDVp7jIvqhlaMW4MVDqsUdyMJiDT13BO3pmk6Ew+flajgEnl gnne6RmtuGjgppzHvkuGAbntg8GN0lvI+YvTt8XtAJ2wZQlzSpM6AYsey8iHZx5JSZ0Q apFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=J99Q6xTXtDj04+Du0fCQJFtCW8HBuU4z5s+dPJzoIYo=; b=sV8KSPL/aX4S6FUayeRlwrFMIs3f5JoamRcK5T5LfW3SfdvKuF+a5EiHKcrPtlwQe+ QgavJSOIz4sqHiMbUqq81da8Zi33T5DdaqkO8vOyMNFIAvn10oWz8TRWEsCRk7dUf9mj xPkZ8UikHmFoxs0UHA16q+msEZFKvAa9ymCjsjvZ0SfjiUMA2P8RNLOEhTEPYkG/HLb+ Krc82ZlKEEbduqVYrClUYU9LaGyXUAu/X3cQpy0aKw3zVVS+nBk44AOH2kh29LdO8H8e hJnBuxftapD+N3LURTiSh6xBv7YVxMddzjbUPARI7fmPh2eymhgZ1oI3u2yzdVTNMWSh UbEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="c3M/xiwo"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c11si169705edn.383.2020.06.03.10.56.19; Wed, 03 Jun 2020 10:56:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="c3M/xiwo"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726207AbgFCR4Q (ORCPT + 99 others); Wed, 3 Jun 2020 13:56:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726103AbgFCR4Q (ORCPT ); Wed, 3 Jun 2020 13:56:16 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2885C08C5C0 for ; Wed, 3 Jun 2020 10:56:15 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id 64so2092026pfg.8 for ; Wed, 03 Jun 2020 10:56:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=J99Q6xTXtDj04+Du0fCQJFtCW8HBuU4z5s+dPJzoIYo=; b=c3M/xiwojAUGzMnptkETJWPfjN8knQc/M9d2XTX7mk+wQDrzyJG08y2MHozUzDfAj/ RlVwjsV06sxAo8UJRklDBCxLxOOIy/F5hlw1Op7XuPEDwkRj5efSv736TRgcMBi1h2Cr 5zqG3LimGpElPEnA+W3mZB4XcOh92GX+vfFYA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=J99Q6xTXtDj04+Du0fCQJFtCW8HBuU4z5s+dPJzoIYo=; b=Wn9TnCbZsg+/HEJCJcTA7ynHLdVGaZQMuJqM50IlPzK24wjdziX2Bz9nQzssyFqkgU cqIreVuoKaqcManfioMhNyLTfkwFJ4AAlhIOfWlKm2qIXT7J42ceNL4TuyIkNUJUGpBp WqMo5D9XBwE5WlYGsYbidNJL4xeQBQtWUXGoot8Lrs++s6vRYa5kQfeW4YCjWEi5kZsZ X87EXmFF7ZOdept3ZnHjhg9/PZip+YCgka6iRdX+LT4PhIq0m3s9Spt7UbpbxZ3v2OQP j8i3xPqEXDVUI+g9X6I3tToa6KDr7eYLAJubQtU6ctoWkU+TjFy7ZAj7BoLnD/GLOTzg 8+eQ== X-Gm-Message-State: AOAM530LcamyqXI+qa+EpxisRA1J8TcuudIOgunatQN2C4cy5ftfY1ca mz9FydO1uI8x24PHbLAFb0HlhkRNMTg= X-Received: by 2002:a63:1a01:: with SMTP id a1mr494583pga.87.1591206975088; Wed, 03 Jun 2020 10:56:15 -0700 (PDT) Received: from sonnysasaka-chrome.mtv.corp.google.com ([2620:15c:202:201:b7e2:9910:bd78:608d]) by smtp.gmail.com with ESMTPSA id t2sm2064518pgh.89.2020.06.03.10.56.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Jun 2020 10:56:14 -0700 (PDT) From: Sonny Sasaka To: linux-bluetooth@vger.kernel.org Cc: Sonny Sasaka Subject: [PATCH] shared/util: Fix undefined behavior of left shift Date: Wed, 3 Jun 2020 10:56:00 -0700 Message-Id: <20200603175600.3006-1-sonnysasaka@chromium.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org 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