From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id CC1523858C83 for ; Wed, 25 Jan 2023 21:21:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CC1523858C83 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: by gnu.wildebeest.org (Postfix, from userid 1000) id 1E4E6302BBEC; Wed, 25 Jan 2023 22:20:59 +0100 (CET) Date: Wed, 25 Jan 2023 22:20:59 +0100 From: Mark Wielaard To: Hannes Domani Cc: "gdb-patches@sourceware.org" , Simon Marchi , Sam James , Tom Tromey , John Baldwin Subject: Re: [PATCHv5] gdb: Replace memcpy with std::copy to avoid some g++ warnings on sparc Message-ID: <20230125212059.GK11538@gnu.wildebeest.org> References: <20230125085538.986074-1-mark@klomp.org> <1405677081.2976403.1674648005737@mail.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1405677081.2976403.1674648005737@mail.yahoo.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-3031.9 required=5.0 tests=BAYES_00,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Hannes, On Wed, Jan 25, 2023 at 12:00:05PM +0000, Hannes Domani wrote: > Am Mittwoch, 25. Januar 2023 um 09:56:03 MEZ hat Mark Wielaard Folgendes geschrieben: > > >   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 ()); > > structsize is of type uint32_t, so wouldn't that effectively copy 4*4 bytes, instead of just 4? > > Shouldn't it rather look like this?: > >   std::copy (&structsize, &structsize + 1, desc.data ()); Aha, yeah, std::copy acts on the whole elements of the input. Maybe less confusing to just keep using memcpy here. It is only the second memcpy that produces the issue on sparc. That also brings down the fix to a simple oneliner. Will sent a v6. Thanks, Mark