From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 64250 invoked by alias); 27 Aug 2018 14:57:36 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 63295 invoked by uid 89); 27 Aug 2018 14:57:09 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.5 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gateway31.websitewelcome.com Received: from gateway31.websitewelcome.com (HELO gateway31.websitewelcome.com) (192.185.143.5) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 27 Aug 2018 14:57:06 +0000 Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway31.websitewelcome.com (Postfix) with ESMTP id 9659C9F114A for ; Mon, 27 Aug 2018 09:56:55 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id uIwMfsH9nbXuJuIwcfDwsg; Mon, 27 Aug 2018 09:56:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=GDtKPGA6HB7/k7O+/j19UP2A5wCCCfHakMZ91WHZfiY=; b=lgFq/jCJwAU5hrJT38pI1EvCv0 vRPlACYpRjgogoDMgnIkLjPyVh/6C9dHBIiW4pGiE0z1YQ5xiU7YMyszoOICy57S1+cQGjbbi8HoS 98QT1q+Y70bNtvY8u9+4qM4fV; Received: from 75-166-85-72.hlrn.qwest.net ([75.166.85.72]:54030 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fuIwL-000csy-FQ; Mon, 27 Aug 2018 09:56:25 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 4/9] Avoid undefined behavior in read_subrange_type Date: Mon, 27 Aug 2018 14:59:00 -0000 Message-Id: <20180827145620.11055-5-tom@tromey.com> In-Reply-To: <20180827145620.11055-1-tom@tromey.com> References: <20180827145620.11055-1-tom@tromey.com> X-SW-Source: 2018-08/txt/msg00658.txt.bz2 -fsanitize=undefined pointed out an undefined shift of a negative value in read_subrange_type. The fix is to do the work in an unsigned type, where this is defined. ChangeLog 2018-08-27 Tom Tromey * dwarf2read.c (read_subrange_type): Make "negative_mask" unsigned. --- gdb/ChangeLog | 5 +++++ gdb/dwarf2read.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 8834d08a1c6..86ef1c4040b 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -17682,7 +17682,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) int low_default_is_valid; int high_bound_is_count = 0; const char *name; - LONGEST negative_mask; + ULONGEST negative_mask; orig_base_type = die_type (die, cu); /* If ORIG_BASE_TYPE is a typedef, it will not be TYPE_UNSIGNED, @@ -17815,7 +17815,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) the bounds as signed, and thus sign-extend their values, when the base type is signed. */ negative_mask = - -((LONGEST) 1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1)); + -((ULONGEST) 1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1)); if (low.kind == PROP_CONST && !TYPE_UNSIGNED (base_type) && (low.data.const_val & negative_mask)) low.data.const_val |= negative_mask; -- 2.13.6