[U-Boot] [PATCH 7/9] setexpr: add regex substring matching and substitution

Marek Vasut marex at denx.de
Fri Mar 22 23:36:59 CET 2013


Dear Wolfgang Denk,

> Add "setexpr name gsub r s [t]" and "setexpr name sub r s [t]"
> commands which implement substring matching for the regular
> expression <r> in the string <t>, and substitution of the string <s>.
> The result is assigned to the environment variable <name>.  If <t> is
> not supplied, the previous value of <name> is used instead.  "gsub"
> performs global substitution, while "sub" will replace only the first
> substring.
> 
[...]

> +static char *memstr(const char *s1, int l1, const char *s2, int l2)
> +{
> +	if (!l2)
> +		return (char *) s1;
> +
> +	while (l1 >= l2) {
> +		l1--;
> +		if (!memcmp(s1, s2, l2))
> +			return (char *) s1;
> +		s1++;
> +	}
> +	return NULL;
> +}

Will this memstr() not crash with wrong parameters? Or is this safe?

btw. there is a checkpatch issue and two warnings:
ERROR: space required after that ';' (ctx:WxV)
#294: FILE: common/cmd_setexpr.c:177:
+       for (loop = 0; ;loop++) {
                       ^

I think the warnings are ok.

Best regards,
Marek Vasut


More information about the U-Boot mailing list