On 03/13/2014 01:48 PM, Wolfgang Denk wrote: > Dear Tom, > > In message <20140313191814.GB16360@bill-the-cat> you wrote: >> >>>> +struct uuid { >>>> + unsigned int time_low; >>>> + unsigned short time_mid; >>>> + unsigned short time_hi_and_version; >>>> + unsigned char clock_seq_hi_and_reserved; >>>> + unsigned char clock_seq_low; >>>> + unsigned char node[6]; >>>> +};
>>>> +void gen_rand_uuid(unsigned char *uuid_bin) >>>> +{ >>>> + struct uuid *uuid = (struct uuid *)uuid_bin; >>> >>> Here you cast a pointer to the (unaligned) character buffer to a >>> struct buffer, which requires alignment. >> >> Potentially unaligned buffer. There's only one caller thus far, and it >> will be aligned there. We do need to comment that the pointer needs to >> be aligned. > > No. We should rather fix the code such that it works with any > alignment. It is trivial here to use a struct uuid on the stack and > then use memcpy() to cpy the data from the struct to the buffer - no > casting needed anywhere, and no alignment concerns either. Why not just change the prototype of the function so that it takes a pointer to a struct uuid. That way, the compiler will ensure that everything is aligned correctly (assuming there are no broken casts at the call site), and we won't have to either document any assumptions about alignment, nor perform a memcpy() to work around any misalignment. _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot