[U-Boot] [PATCH 1/4] cmdline: Add linux command line munging tools

Mike Frysinger vapier at gentoo.org
Thu Oct 20 00:46:09 CEST 2011


On Wednesday 19 October 2011 18:30:56 Doug Anderson wrote:
> --- /dev/null
> +++ b/common/cmdline.c
>
> +/*
> + * To run unit tests in this file:
> + *   gcc -DRUN_UNITTESTS -Wall -Werror common/cmdline.c -o cmdline &&
> ./cmdline
> + */
> +#ifdef RUN_UNITTESTS

i'm not sure this part should be merged ... better to keep on the back burner 
while Simon sorts out testing framework with new sandbox arch.

> +void add_cmdline_param(char *cmdline, const char *toappend, int bufsize)

bufsize should be size_t

> +{
> +	int cmdline_len = strlen(cmdline);

cmdline_len should be size_t

> +	if (cmdline_len == 0)
> +		strncat(cmdline, toappend, bufsize-1);
> +	else {
> +		int bytes_avail = bufsize - cmdline_len;
> +
> +		if (bytes_avail <= 0) {
> +			assert(bytes_avail == 0);
> +			return;
> +		}
> +		cmdline[bufsize-1] = '\0';
> +		cmdline[cmdline_len] = ' ';
> +		strncpy(&cmdline[cmdline_len+1], toappend,
> +			bytes_avail-2);
> +	}

hmm, i feel like this should be simpler and not need that branch

	if (cmdline_len)
		cmdline[cmdline_len++] = ' ';
	if (bufsize <= cmdline_len)
		return;
	memcpy(&cmdline[cmdline_len], toappend, bufsize - cmdline_len - 1);
	cmdline[bufsize] = '\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/20111019/bf949527/attachment.pgp 


More information about the U-Boot mailing list