[SLOF] [PATCH 1/4] romfs/tools: Remove superfluous union around the rom header struct

Segher Boessenkool segher at kernel.crashing.org
Thu Jul 19 00:35:15 AEST 2018


On Wed, Jul 18, 2018 at 02:41:41PM +0200, Thomas Huth wrote:
> -	union {
> -		unsigned char pcArray[FLASHFS_HEADER_DATA_SIZE];
> -		struct stH stHeader;
> -	} uHeader;
> +	struct stH stHeader;
> +
> +	assert(sizeof(stHeader) == FLASHFS_HEADER_DATA_SIZE);
>  
>  	/* initialize Header */
> -	memset(uHeader.pcArray, 0x00, FLASHFS_HEADER_DATA_SIZE);
> +	memset(&stHeader, 0x00, FLASHFS_HEADER_DATA_SIZE);

It would be nice to have a build-time assert for this.

You can also get rid of this explicit memset by doing this as

	assert(sizeof(stHeader) == FLASHFS_HEADER_DATA_SIZE);

	struct stH stHeader = { 0 } ;


Segher


More information about the SLOF mailing list