From patchwork Fri Jul 27 17:25:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 28651 Received: (qmail 51600 invoked by alias); 27 Jul 2018 17:26:25 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 51454 invoked by uid 89); 27 Jul 2018 17:26:23 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.7 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=excludes, complaints X-HELO: gateway23.websitewelcome.com Received: from gateway23.websitewelcome.com (HELO gateway23.websitewelcome.com) (192.185.49.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 27 Jul 2018 17:26:22 +0000 Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway23.websitewelcome.com (Postfix) with ESMTP id 63083134FB for ; Fri, 27 Jul 2018 12:26:21 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id j6V8fHiqgbXuJj6VJfNwUF; Fri, 27 Jul 2018 12:26:20 -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=GSvk7NpN9PvY7PDd3B8cLYZspGLhQpDiEnEnpoSsdhI=; b=cIWZTFMsVUpTBr5qK3vvwDIu3v VcYyoC7uVfk+sXwzgdK8OG8Ki6yc/RfLRTn6tGsP30IyzP/0xxlTwgG/+VYCVtzhW2EsgbrZHr2Yu rB5YgXQWHiZ7Cfmg9g/98AIzG; Received: from 75-166-85-72.hlrn.qwest.net ([75.166.85.72]:50616 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fj6V8-003MVN-MC; Fri, 27 Jul 2018 12:26:02 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/3] Do not pass NULL to memcpy Date: Fri, 27 Jul 2018 11:25:58 -0600 Message-Id: <20180727172600.15994-2-tom@tromey.com> In-Reply-To: <20180727172600.15994-1-tom@tromey.com> References: <20180727172600.15994-1-tom@tromey.com> I built gdb with -fsanitize=undefined and ran the test suite. This patch fixes a couple of complaints that occur when passing NULL to memcpy, which is undefined behavior according to the C standard. gdb/ChangeLog 2018-07-27 Tom Tromey * namespace.c (add_using_directive): Don't pass NULL to memcpy. * dwarf2-frame.h (struct dwarf2_frame_state_reg_info): Don't pass NULL to memcpy. --- gdb/ChangeLog | 6 ++++++ gdb/dwarf2-frame.h | 3 ++- gdb/namespace.c | 5 +++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/gdb/dwarf2-frame.h b/gdb/dwarf2-frame.h index 52316e5e168..6844010c8df 100644 --- a/gdb/dwarf2-frame.h +++ b/gdb/dwarf2-frame.h @@ -110,7 +110,8 @@ struct dwarf2_frame_state_reg_info size_t size = src.num_regs * sizeof (struct dwarf2_frame_state_reg); reg = (struct dwarf2_frame_state_reg *) xmalloc (size); - memcpy (reg, src.reg, size); + if (size > 0) + memcpy (reg, src.reg, size); } /* Assignment operator for both move-assignment and copy-assignment. */ diff --git a/gdb/namespace.c b/gdb/namespace.c index be998d9d491..85c0c4b14d7 100644 --- a/gdb/namespace.c +++ b/gdb/namespace.c @@ -111,8 +111,9 @@ add_using_directive (struct using_direct **using_directives, else newobj->declaration = declaration; - memcpy (newobj->excludes, excludes.data (), - excludes.size () * sizeof (*newobj->excludes)); + if (!excludes.empty ()) + memcpy (newobj->excludes, excludes.data (), + excludes.size () * sizeof (*newobj->excludes)); newobj->excludes[excludes.size ()] = NULL; newobj->next = *using_directives;