public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Mark Wielaard <mark@klomp.org>,
	gdb-patches@sourceware.org, John Baldwin <jhb@FreeBSD.org>
Cc: Sam James <sam@gentoo.org>, Tom Tromey <tom@tromey.com>
Subject: Re: [PATCHv3] gdb: Replace memcpy with std::copy to avoid some g++ warnings on sparc
Date: Tue, 24 Jan 2023 16:29:20 -0500	[thread overview]
Message-ID: <2f5e28eb-a5f2-0995-506f-b6632333c7b2@simark.ca> (raw)
In-Reply-To: <20230124201624.875658-1-mark@klomp.org>



On 1/24/23 15:16, Mark Wielaard wrote:
> For some reason g++ 12.2.1 on sparc produces a spurious warnings for
> stringop-overread and restrict in fbsd-tdep.c for some memcpy calls.
> Use std::copy to avoid those.
> 
> In function ‘void* memcpy(void*, const void*, size_t)’,
>     inlined from ‘gdb::optional<std::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > > > fbsd_make_note_desc(target_object, uint32_t)’ at ../../binutils-gdb/gdb/fbsd-tdep.c:666:10:
> /usr/include/bits/string_fortified.h:29:33: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ specified bound 18446744073709551612 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]
> 
> In function ‘void* memcpy(void*, const void*, size_t)’,
>     inlined from ‘gdb::optional<std::vector<unsigned char, gdb::default_init_allocator<unsigned char, std::allocator<unsigned char> > > > fbsd_make_note_desc(target_object, uint32_t)’ at ../../binutils-gdb/gdb/fbsd-tdep.c:673:10:
> /usr/include/bits/string_fortified.h:29:33: error: ‘void* __builtin_memcpy(void*, const void*, long unsigned int)’ accessing 18446744073709551612 bytes at offsets 0 and 0 overlaps 9223372036854775801 bytes at offset -9223372036854775805 [-Werror=restrict]
> 
> gdb/ChangeLog:
> 
> 	* fbsd-tdep.c (fbsd_make_note_desc): Use std::copy instead
> 	of memcpy.
> ---
> 
> V3: Drop diagnostic suppressions just use std::copy
> V2: Fix typos and add example errors to commit messages
> 
>  gdb/fbsd-tdep.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c
> index 203390d9880..ebc15543149 100644
> --- a/gdb/fbsd-tdep.c
> +++ b/gdb/fbsd-tdep.c
> @@ -662,8 +662,9 @@ fbsd_make_note_desc (enum target_object object, uint32_t structsize)
>      return buf;
>  
>    gdb::byte_vector desc (sizeof (structsize) + buf->size ());
> -  memcpy (desc.data (), &structsize, sizeof (structsize));
> -  memcpy (desc.data () + sizeof (structsize), buf->data (), buf->size ());
> +  std::copy (&structsize, &structsize + sizeof (structsize), desc.data ());
> +  std::copy (buf->data (), desc.data () + sizeof (structsize),
> +	     desc.data () + sizeof (structsize));

I think the second argument to the second std::copy call should have
`buf->data ()`, not `desc.data ().  Otherwise, LGTM.  However, it would
be nice to have the approval from John Baldwin.

Simon

  reply	other threads:[~2023-01-24 21:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-24 20:16 Mark Wielaard
2023-01-24 21:29 ` Simon Marchi [this message]
2023-01-24 21:49   ` Mark Wielaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2f5e28eb-a5f2-0995-506f-b6632333c7b2@simark.ca \
    --to=simark@simark.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=jhb@FreeBSD.org \
    --cc=mark@klomp.org \
    --cc=sam@gentoo.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).