
24 Mar
2013
24 Mar
'13
10:38 a.m.
Dear Marek,
In message 201303222337.00146.marex@denx.de you wrote:
+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?
I'm not sure thwat you mean by "will it crash" / "is this safe"?
Of course you can pass bogus parameters that will cause issues - in the very same way as you can do it with existing standard functions like memcmp() or strstr().
Or do you see any specific problems in above code.
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++) {
Will fix that (though I'm not sure if the result is easier to read).
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
The explanation requiring the fewest assumptions is the most likely
to be correct. -- William of Occam