Ethereal-dev: Re: [Ethereal-dev] TVBuff: tvb_memcpy

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: David Frascone <dave@xxxxxxxxxxxx>
Date: Wed, 21 Mar 2001 13:56:54 -0600
Most compilers have a way to set packing.  But, it would make for a VERY
nasty #ifdef tree.

I think you can reasonably safely assume that if you keep everything 32 bit
aligned, it will work.  I can't think off the top of my head of any machine
that would break.

On Wed, Mar 21, 2001 at 12:11:03PM -0600, Gilbert Ramirez wrote:
> Michal.Melerowicz@xxxxxxxxx wrote:
> > 
> > > Hi all,
> > >
> > > I have question regarding tvbuff:
> > >
> > > I've got very strange behaviour of tvbuffs (strange for me of course).
> > > There is a structure (below) I defined. I'm trying to copy 118 bytes from
> > > tvbuff to myvar (type of mystruct), and what I got:
> 
> > >
> > > /* same result
> > >           tvb_memcpy(tvb, (guint8*)&myvar, offset+3, 93);
> > >           tvb_memcpy(tvb, ((guint8*)&myvar)+93, offset+93, 25);
> > >
> > >           myvar = (struct_t *)tvb_memdup(tvb, offset+3, 118);*/
> > >
> > > }
> 
> Even though Ethereal itself sets a bad example in some places,
> you cannot portably copy an array of bytes onto a struct and expect
> a one-to-one correlation. The compiler may not have packed the
> fields in the struct next to each other --- there may be padding
> between fields. The only thing the ANSI C spec guarantees is the
> *order* of the fields in the struct, not their closeness.
> 
> GCC has a way of specifying a struct as being packed, but we
> don't want to limit Ethereal to being compiled only by gcc.
> 
> We need to fix the occurences of this bad practice that already
> exist in ethereal.
> 
> --gilbert
> 
> _______________________________________________
> Ethereal-dev mailing list
> Ethereal-dev@xxxxxxxxxxxx
> http://www.ethereal.com/mailman/listinfo/ethereal-dev