On Mon, Aug 18, 2014 at 11:58:09AM -0600, Simon Glass wrote:
> On 18 August 2014 01:16, Thierry Reding <[email protected]> wrote:
[...]
> > +int fdt_get_string_index(const void *fdt, int node, const char *property,
> > +                        const char *string)
> > +{
> > +       const char *list, *end;
> > +       int len, index = 0;
> > +
> > +       list = fdt_getprop(fdt, node, property, &len);
> > +       if (!list)
> > +               return len;
> > +
> > +       end = list + len;
> > +
> > +       while (list < end) {
> > +               int n = strlen(string);
> 
> This can go outside the loop.

Indeed.

> > +               int m = strlen(list);
> > +
> > +               if (n == m && memcmp(list, string, n) == 0)
> > +                       return index;
> > +
> > +               list += max(n, m) + 1;
> 
> I worry that if n > m this will end up in the middle of a the next
> string in the list. What is the intention here?

I can no longer recall why that's there. It certainly seems wrong since
if the current substring isn't what we're looking for the function
should proceed to the next one, which is always m + 1 characters away.

I'll replace this with list += m + 1.

Thierry

Attachment: pgpPfmFh3enO6.pgp
Description: PGP signature

_______________________________________________
U-Boot mailing list
[email protected]
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to