From patchwork Fri Dec 14 00:15:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 10730137 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BC72013BF for ; Fri, 14 Dec 2018 00:15:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF10C2CDFD for ; Fri, 14 Dec 2018 00:15:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A39762CEF2; Fri, 14 Dec 2018 00:15:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 591FC2CDFD for ; Fri, 14 Dec 2018 00:15:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728423AbeLNAPy (ORCPT ); Thu, 13 Dec 2018 19:15:54 -0500 Received: from mail-ed1-f67.google.com ([209.85.208.67]:33922 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727245AbeLNAPy (ORCPT ); Thu, 13 Dec 2018 19:15:54 -0500 Received: by mail-ed1-f67.google.com with SMTP id b3so3578618ede.1 for ; Thu, 13 Dec 2018 16:15:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SklLcsWgEdJxMRzBq9kshbAxAipmWafTQ6jONGNxKKM=; b=pX1agDS0VgXdmNpi2sITy25z9qkS+d5dHzTMKQJ4u7zeg0DsjXRKRY62i/5wTdBaJh 2OU4mfz2IR9Tp0CfMOpmY6eb0e4HHVhdx4KoJu5r56mq2lxvUHXqGE990w/hnNPwP9tn eu4w4Br0G7E6CaHqWI3f6Zm0YPIIIB6a6oXoyS2bV79u9f2hIDC8wVVwjH8BgTbEkO0J OhwITwTMu7Hx/NcovKOCIgWesDJUtHlB7wWFhX2FRj6ID+FJ04/JzCxi6ssgsh55S5H8 JXUgvBk+jp7Lytm6VpMeh/l1/alSXqe0B0P792nPCZVQNECpQA56u1w69AOq4+lDV1cX eUog== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=SklLcsWgEdJxMRzBq9kshbAxAipmWafTQ6jONGNxKKM=; b=HfpyCI7L/qIdTSo6Xob9yDirrTcT7CVrSuWMTR86ac15CKr/jkaRWDZ2+endWmg/tc jahQ7SMdVAD06iAqfuu0T3UogdU9Z9aGzVl+SmkdLy3Uj9C9SFW8QsphM6+ZT9A9kLTP 3o4w7qiHowgVXzcBCBfQ3h1erz/N/FWHxAnLOIyZY82V/YCWfTp8sSYuIWHSMx5vG0Wz K5qUHnDVsGqBsNHmwj3I7FFKWuTUMxpkyQgMgldbJpt/UkjcZT9c13xsoRiLQHCbVEm9 NFD7Ndb7636nO8AdNR4IDi4oQSiuyOxz8v7EE5qGpPHh/hhN9G72zcaK5ZteHxDdWGhz 2CiA== X-Gm-Message-State: AA+aEWapYnnYJysSDLxcqFkxDBWYLl1Qir1n+uMqu7wuEP49qsgRKdXH 1JiL3bZX2DiosWljKoh4QZFBO9I6 X-Google-Smtp-Source: AFSGD/V+kmHTZoxgz9TwCA72GnzdomDL3gZe95N2jo+c6tlkFazJ733A+0G4XKU1677P3rb2Y4PO+A== X-Received: by 2002:aa7:d416:: with SMTP id z22mr1048571edq.3.1544746551929; Thu, 13 Dec 2018 16:15:51 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:4081:8a00:5930:404c:ddbe:1aaf]) by smtp.gmail.com with ESMTPSA id f20sm986489edf.19.2018.12.13.16.15.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Dec 2018 16:15:51 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Ramsay Jones , Luc Van Oostenryck Subject: [PATCH v3 07/19] use bits_mask() for predefined_max() Date: Fri, 14 Dec 2018 01:15:24 +0100 Message-Id: <20181214001536.6259-8-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181214001536.6259-1-luc.vanoostenryck@gmail.com> References: <20181214001536.6259-1-luc.vanoostenryck@gmail.com> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Creating a bit mask using '(1 << n) - 1' is undefined if n is as big as the width of an int. Use the safe helper bits_mask() to create the mask/value for predefined_max(). Note: predefined_max() is currently correct only for signed types. Signed-off-by: Luc Van Oostenryck --- lib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib.c b/lib.c index 70c5c72bb..8cd2a837f 100644 --- a/lib.c +++ b/lib.c @@ -46,6 +46,7 @@ #include "target.h" #include "machine.h" #include "version.h" +#include "bits.h" int verbose, optimize_level, optimize_size, preprocessing; int die_if_error = 0; @@ -1142,7 +1143,7 @@ static void predefined_width(const char *name, unsigned bits) static void predefined_max(const char *name, const char *suffix, unsigned bits) { - unsigned long long max = (1ULL << (bits - 1 )) - 1; + unsigned long long max = bits_mask(bits - 1); char buf[32]; snprintf(buf, sizeof(buf), "__%s_MAX__", name);