On Wed, Sep 1, 2021 at 3:26 PM Ryan Long <ryan.l...@oarcorp.com> wrote:
>
>
>
> -----Original Message-----
> From: Gedare Bloom <ged...@rtems.org>
> Sent: Wednesday, September 1, 2021 3:21 PM
> To: Ryan Long <ryan.l...@oarcorp.com>
> Cc: devel@rtems.org
> Subject: Re: [PATCH] TraceWriterQEMU.cc: Change strncpy to memcpy
>
> On Thu, Aug 19, 2021 at 7:42 AM Ryan Long <ryan.l...@oarcorp.com> wrote:
> >
> > CID 1506207: Buffer not null terminated
> >
> > Closes #4491
> > ---
> >  tester/covoar/TraceWriterQEMU.cc | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/tester/covoar/TraceWriterQEMU.cc
> > b/tester/covoar/TraceWriterQEMU.cc
> > index c417745..be9b6e1 100644
> > --- a/tester/covoar/TraceWriterQEMU.cc
> > +++ b/tester/covoar/TraceWriterQEMU.cc
> > @@ -106,7 +106,10 @@ namespace Trace {
> >      //
> >      //  Write the Header to the file
> >      //
> > -    strncpy( header.magic, QEMU_TRACE_MAGIC, sizeof(header.magic) );
> > +    // The header.magic field is actually 12 bytes, but QEMU_TRACE_MAGIC is
> > +    // 13 bytes including the NULL.
> > +    const char qemu_trace_magic[13] = QEMU_TRACE_MAGIC;
> > +    memcpy( header.magic, qemu_trace_magic, sizeof(header.magic) );
>
> Just to clarify, the header.magic should not be NULL terminated?
> [Ryan Long] Correct. When I tried to increase the size of header.magic, it 
> wouldn't run correctly.
>
> If so, then this is fine, but I don't think the temporary local variable is 
> needed though.
> memcpy( header.magic, QEMU_TRACE_MAGIC, sizeof(header.magic) ); should work 
> fine.

The qemu trace format for couverture has that format without the NUL
termination.
I'm not sure in their rationale for doing it that way but it is 12 magic bytes.

>
> >      header.version = QEMU_TRACE_VERSION;
> >      header.kind    = QEMU_TRACE_KIND_RAW;  // XXX ??
> >      header.sizeof_target_pc = 32;
> > --
> > 1.8.3.1
> >
> > _______________________________________________
> > devel mailing list
> > devel@rtems.org
> > http://lists.rtems.org/mailman/listinfo/devel
> _______________________________________________
> devel mailing list
> devel@rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
_______________________________________________
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Reply via email to