On Tue, 2011-08-09 at 16:50 -0700, Richard Henderson wrote:
> > 
> > I think I like using a union to ensure the alignment of checksum better.
> > In dwarf2out.c we are always using one md5_ctx structure and one
> > checksum buffer but in fold-const.c there are routines where we use one
> > md5_ctx structure with 4 (fold_build2_stat_loc) or 6
> > (fold_build3_stat_loc) different checksum buffers.
> 
> I'm not keen on this.
> 
> Yes, it does happen to work, but only accidentally.  The CTX
> object and the CHECKSUM object have overlapping lifetimes
> within md5_read_ctx.
> 
> 
> r~

I am not proposing we put the CTX object and the CHECKSUM object into
one union.  I am proposing we leave the CTX object alone and put the
CHECKSUM object in a union with a dummy variable of type md5_uint32 in
order to ensure that the CHECKSUM object has the correct alignment.

So the usage would be:

union md5_resbuf
{
  md5_uint32 dummy;                     /* Unused variable used to ensure 
alignment */
  unsigned char resbuf[16];             /* The buffer we are using in 
md5_finish_ctx */
};

struct md5_ctx ctx;                     /* Same as before */
union md5_resbuf checksum;              /* Instead of unsigned char 
checksum[16]; */
md5_finish_ctx (&ctx, checksum.resbuf); /* instead of md5_finish_ctx (&ctx, 
checksum); */

Steve Ellcey
s...@cup.hp.com

Reply via email to