public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Reference array of structs instead of first member during memcpy
@ 2022-01-25 16:39 Keith Seitz
  2022-01-25 21:44 ` Kevin Buettner
  0 siblings, 1 reply; 3+ messages in thread
From: Keith Seitz @ 2022-01-25 16:39 UTC (permalink / raw)
  To: 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Reference array of structs instead of first member during memcpy
  2022-01-25 16:39 [PATCH] Reference array of structs instead of first member during memcpy Keith Seitz
@ 2022-01-25 21:44 ` Kevin Buettner
  2022-01-26 17:31   ` Keith Seitz
  0 siblings, 1 reply; 3+ messages in thread
From: Kevin Buettner @ 2022-01-25 21:44 UTC (permalink / raw)
  To: Keith Seitz via Gdb-patches

On Tue, 25 Jan 2022 08:39:00 -0800
Keith Seitz via Gdb-patches <gdb-patches@sourceware.org> wrote:

> The simple fix is to reference the array, `MEMS' as the destination of the copy.

LGTM.

Kevin


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Reference array of structs instead of first member during memcpy
  2022-01-25 21:44 ` Kevin Buettner
@ 2022-01-26 17:31   ` Keith Seitz
  0 siblings, 0 replies; 3+ messages in thread
From: Keith Seitz @ 2022-01-26 17:31 UTC (permalink / raw)
  To: Kevin Buettner, Keith Seitz via Gdb-patches

On 1/25/22 13:44, Kevin Buettner wrote:
> On Tue, 25 Jan 2022 08:39:00 -0800
> Keith Seitz via Gdb-patches <gdb-patches@sourceware.org> wrote:
> 
>> The simple fix is to reference the array, `MEMS' as the destination of the copy.
> 
> LGTM.

I've pushed this patch. Thank you for taking a look, Kevin!

Keith


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-26 17:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-25 16:39 [PATCH] Reference array of structs instead of first member during memcpy Keith Seitz
2022-01-25 21:44 ` Kevin Buettner
2022-01-26 17:31   ` Keith Seitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).