[U-Boot] [PATCH 02/12] tools/env: Remove unneeded complexity

Mike Frysinger vapier at gentoo.org
Thu Aug 23 05:30:07 CEST 2012


On Friday 17 August 2012 16:49:36 Joe Hershberger wrote:
> --- a/tools/env/fw_env.c
> +++ b/tools/env/fw_env.c
> 
> -			memset(value, 0, len - strlen(name));
> +			memset(value, 0, len);

side note: this memset is mostly useles as the value buffer largely gets 
written.  all it should be is:
	value[len - 1] = '\0';

similarly, this logic at the end:
	if (value)
		free(value);
that "if" check is pointless as free(NULL) works fine

if you really wanted, the whole loop could be rewritten to use realloc

	for (i = 2; i < argc; ++i) {
		const char *val = argv[i];
		size_t val_len = strlen(val);

		value = realloc(value, len + val_len + 1);
		if (!value) {
			fprintf(...);
			return -1;
		}

		memcpy(value + len, val, val_len);
		len += val_len;
		value[len++] = ' ';
	}
	value[len - 1] = '\0';
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120822/149260b8/attachment.pgp>


More information about the U-Boot mailing list