From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thierry Reding Date: Tue, 19 Aug 2014 13:13:02 +0200 Subject: [U-Boot] [PATCH 02/23] fdt: Add a function to get the index of a string In-Reply-To: References: <1408346196-30419-1-git-send-email-thierry.reding@gmail.com> <1408346196-30419-3-git-send-email-thierry.reding@gmail.com> Message-ID: <20140819111301.GB19515@ulmo> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Mon, Aug 18, 2014 at 11:58:09AM -0600, Simon Glass wrote: > On 18 August 2014 01:16, Thierry Reding 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 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 819 bytes Desc: not available URL: