From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 64195 invoked by alias); 27 Aug 2018 14:57:35 -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 63457 invoked by uid 89); 27 Aug 2018 14:57:10 -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=preceding, *exp X-HELO: gateway30.websitewelcome.com Received: from gateway30.websitewelcome.com (HELO gateway30.websitewelcome.com) (192.185.150.24) 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 gateway30.websitewelcome.com (Postfix) with ESMTP id 70C5B1C085 for ; Mon, 27 Aug 2018 09:56:56 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id uIwOfsHGQbXuJuIwffDx0b; Mon, 27 Aug 2018 09:56:56 -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=pTmUnPo//G1mUVNGe57in2QvcTwDvQQJlJ1Glvo60Ds=; b=siCjWmyYJA/DzVawH1tRWowFCX BHYXXO+JufsGeaEnmoqOd3a67mZShP+1eePTUFdaIXqU2ZqLZAf61DcAxNgPpIGLD9A5kedMMoJHl SP/sy/1B98Om/42ZkLFTdjDMU; 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 1fuIwN-000csy-R1; Mon, 27 Aug 2018 09:56:28 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 8/9] Avoid undefined behavior in expression dumping Date: Mon, 27 Aug 2018 14:59:00 -0000 Message-Id: <20180827145620.11055-9-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/msg00659.txt.bz2 -fsanitize=undefined pointed out undefined behavior in dump_raw_expression like: runtime error: load of value 2887952, which is not a valid value for type 'exp_opcode' dump_raw_expression will try to print the opcode for each element of the expression, even when it is not valid. To allow this, but have it avoid undefined behavior, this patch sets the underlying type of enum exp_opcode, and arranges for op_name to handle invalid opcodes more nicely. ChangeLog 2018-08-27 Tom Tromey * expression.h (enum exp_opcode): Use uint8_t as base type. * expprint.c (op_name): Handle invalid opcodes. --- gdb/ChangeLog | 5 +++++ gdb/expprint.c | 6 ++++++ gdb/expression.h | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/gdb/expprint.c b/gdb/expprint.c index d6ed41253ed..7c91cc73749 100644 --- a/gdb/expprint.c +++ b/gdb/expprint.c @@ -687,6 +687,12 @@ static int dump_subexp_body (struct expression *exp, struct ui_file *, int); const char * op_name (struct expression *exp, enum exp_opcode opcode) { + if (opcode >= OP_UNUSED_LAST) + { + char *cell = get_print_cell (); + xsnprintf (cell, PRINT_CELL_SIZE, "unknown opcode: %d", int (opcode)); + return cell; + } return exp->language_defn->la_exp_desc->op_name (opcode); } diff --git a/gdb/expression.h b/gdb/expression.h index 9f26bb8d60b..db572efe2a3 100644 --- a/gdb/expression.h +++ b/gdb/expression.h @@ -39,7 +39,7 @@ and skip that many. Strings, like numbers, are indicated by the preceding opcode. */ -enum exp_opcode +enum exp_opcode : uint8_t { #define OP(name) name , -- 2.13.6