[SLOF] [PATCH v2 3/4] romfs/tools: Silence more compiler warnings with GCC 8.1

Segher Boessenkool segher at kernel.crashing.org
Sun Jul 22 02:46:52 AEST 2018


Hi!

On Thu, Jul 19, 2018 at 02:46:26PM +0200, Thomas Huth wrote:
> +#define min(a, b) ((a) < (b) ? (a) : (b))

This function-like macro isn't very function-like (it does (potential)
double evaluation of its arguments, it can exhibit UB where a function
cannot, etc.)  Write this as an inline function?  Or at the very least
give it nature's yellow-and-black-warning stripes, which is ALL CAPS
in C ;-)

> +	pcVersion = getenv("DRIVER_NAME");
> +	if (!pcVersion)
> +		pcVersion = getenv("USER");
> +	if (!pcVersion)
> +		pcVersion = "unknown";
> +	memcpy(stHeader.version, pcVersion,
> +	       min(strlen(pcVersion), sizeof(stHeader.version)));

You would think there should be a nicer way to do this.  I don't see
it either.


Segher


More information about the SLOF mailing list