From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id cXO+Ar0n8GH8eQAAWB0awg (envelope-from ) for ; Tue, 25 Jan 2022 11:39:25 -0500 Received: by simark.ca (Postfix, from userid 112) id EDDAC1F3B6; Tue, 25 Jan 2022 11:39:24 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 475711EE18 for ; Tue, 25 Jan 2022 11:39:24 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AE3B7385B83D for ; Tue, 25 Jan 2022 16:39:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AE3B7385B83D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1643128763; bh=VzPxx5cjtz18sel7Ow2Zgw8hN9hCE1w7tUQlhkrZLas=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=eoR0WgNWoL/4SfjN3Z23AQyXbce6v1+wFelCbZPmROXWapJcEhLxE2vihJd3AzAkD EFXAnuPuf477MGd2MEyBg/jZABjax/Z2Y7CZIdkYsxm4B8g9WoJbyLPIDMyGNITzSM sQxkFCHtb7FR9S6QJLBhFbJ/X+EZ958d8jAuC3Ds= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id BD6F63857C70 for ; Tue, 25 Jan 2022 16:39:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BD6F63857C70 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-629-utt6TcH4OgmqHmfbM-KL1Q-1; Tue, 25 Jan 2022 11:39:03 -0500 X-MC-Unique: utt6TcH4OgmqHmfbM-KL1Q-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 644651080865 for ; Tue, 25 Jan 2022 16:39:02 +0000 (UTC) Received: from guittard.uglyboxes.com (unknown [10.2.16.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id BDCA6798C6 for ; Tue, 25 Jan 2022 16:39:01 +0000 (UTC) To: gdb-patches@sourceware.org Subject: [PATCH] Reference array of structs instead of first member during memcpy Date: Tue, 25 Jan 2022 08:39:00 -0800 Message-Id: <20220125163900.800317-1-keiths@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Keith Seitz via Gdb-patches Reply-To: Keith Seitz Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" aarch64-tdep.c defines the following macro: #define MEM_ALLOC(MEMS, LENGTH, RECORD_BUF) \ do \ { \ unsigned int mem_len = LENGTH; \ if (mem_len) \ { \ MEMS = XNEWVEC (struct aarch64_mem_r, mem_len); \ memcpy(&MEMS->len, &RECORD_BUF[0], \ sizeof(struct aarch64_mem_r) * LENGTH); \ } \ } \ while (0) This is simlpy allocating a new array and copying it. However, for the destination address, it is actually copying into the first member of the first element of the array (`&MEMS->len"). This elicits a warning with GCC 12: ../../binutils-gdb/gdb/aarch64-tdep.c: In function ‘int aarch64_process_record(gdbarch*, regcache*, CORE_ADDR)’: ../../binutils-gdb/gdb/aarch64-tdep.c:3711:23: error: writing 16 bytes into a region of size 8 [-Werror=stringop-overflow=] 3711 | memcpy(&MEMS->len, &RECORD_BUF[0], \ | ^ ../../binutils-gdb/gdb/aarch64-tdep.c:4394:3: note: in expansion of macro ‘MEM_ALLOC’ 4394 | MEM_ALLOC (aarch64_insn_r->aarch64_mems, aarch64_insn_r->mem_rec_count, | ^~~~~~~~~ ../../binutils-gdb/gdb/aarch64-tdep.c:3721:12: note: destination object ‘aarch64_mem_r::len’ of size 8 3721 | uint64_t len; /* Record length. */ | ^~~ The simple fix is to reference the array, `MEMS' as the destination of the copy. Tested by rebuilding. # Please enter the commit message for your changes. Lines starting # with '#' will be kept; you may remove them yourself if you want to. # An empty message aborts the commit. # # Date: Tue Jan 25 08:28:32 2022 -0800 # # On branch master # Your branch is ahead of 'origin/master' by 1 commit. # (use "git push" to publish your local commits) # # Changes to be committed: # modified: aarch64-tdep.c # --- gdb/aarch64-tdep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index 63d626f90ac..b3efb3ebaff 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -3708,7 +3708,7 @@ When on, AArch64 specific debugging is enabled."), if (mem_len) \ { \ MEMS = XNEWVEC (struct aarch64_mem_r, mem_len); \ - memcpy(&MEMS->len, &RECORD_BUF[0], \ + memcpy(MEMS, &RECORD_BUF[0], \ sizeof(struct aarch64_mem_r) * LENGTH); \ } \ } \ -- 2.31.1