From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marek Vasut Date: Fri, 22 Mar 2013 23:36:59 +0100 Subject: [U-Boot] [PATCH 7/9] setexpr: add regex substring matching and substitution In-Reply-To: <1363988699-6410-8-git-send-email-wd@denx.de> References: <1320609172-3157-1-git-send-email-wd@denx.de> <1363988699-6410-1-git-send-email-wd@denx.de> <1363988699-6410-8-git-send-email-wd@denx.de> Message-ID: <201303222337.00146.marex@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 in the string , and substitution of the string . > The result is assigned to the environment variable . If is > not supplied, the previous value of 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