public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Fix util_is_printable_string
@ 2013-01-04 19:12 Pantelis Antoniou
  2013-01-05 12:49 ` David Gibson
  2013-01-06 21:38 ` Jon Loeliger
  0 siblings, 2 replies; 3+ messages in thread
From: Pantelis Antoniou @ 2013-01-04 19:12 UTC (permalink / raw)
  To: Jon Loeliger
  Cc: Grant Likely, Rob Herring, devicetree-discuss, linux-kernel,
	Matt Porter, Russ Dill, Pantelis Antoniou

The method used did not account for multi-part strings.

Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>
---
 util.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/util.c b/util.c
index 2422c34..45f186b 100644
--- a/util.c
+++ b/util.c
@@ -72,7 +72,7 @@ char *join_path(const char *path, const char *name)
 int util_is_printable_string(const void *data, int len)
 {
 	const char *s = data;
-	const char *ss;
+	const char *ss, *se;
 
 	/* zero length is not */
 	if (len == 0)
@@ -82,13 +82,19 @@ int util_is_printable_string(const void *data, int len)
 	if (s[len - 1] != '\0')
 		return 0;
 
-	ss = s;
-	while (*s && isprint(*s))
-		s++;
+	se = s + len;
 
-	/* not zero, or not done yet */
-	if (*s != '\0' || (s + 1 - ss) < len)
-		return 0;
+	while (s < se) {
+		ss = s;
+		while (s < se && *s && isprint(*s))
+			s++;
+
+		/* not zero, or not done yet */
+		if (*s != '\0' || s == ss)
+			return 0;
+
+		s++;
+	}
 
 	return 1;
 }
-- 
1.7.12


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: Fix util_is_printable_string
  2013-01-04 19:12 Fix util_is_printable_string Pantelis Antoniou
@ 2013-01-05 12:49 ` David Gibson
  2013-01-06 21:38 ` Jon Loeliger
  1 sibling, 0 replies; 3+ messages in thread
From: David Gibson @ 2013-01-05 12:49 UTC (permalink / raw)
  To: Pantelis Antoniou
  Cc: Jon Loeliger, Matt Porter, devicetree-discuss, linux-kernel,
	Rob Herring, Russ Dill

[-- Attachment #1: Type: text/plain, Size: 740 bytes --]

On Fri, Jan 04, 2013 at 09:12:58PM +0200, Pantelis Antoniou wrote:
> The method used did not account for multi-part strings.
> 
> Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>

I think it could do with some more commenting of exactly what it's
considering a printable string(s).  I'm pretty sure it's doing the
right thing, but if you're not already familiar with the OF
multi-string convention, it would be easy to get confused by the
code.  Other than that

Acked-by: David Gibson <david@gibson.dropbear.id.au>

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Fix util_is_printable_string
  2013-01-04 19:12 Fix util_is_printable_string Pantelis Antoniou
  2013-01-05 12:49 ` David Gibson
@ 2013-01-06 21:38 ` Jon Loeliger
  1 sibling, 0 replies; 3+ messages in thread
From: Jon Loeliger @ 2013-01-06 21:38 UTC (permalink / raw)
  To: Pantelis Antoniou
  Cc: Grant Likely, Rob Herring, devicetree-discuss, linux-kernel,
	Matt Porter, Russ Dill

> The method used did not account for multi-part strings.
> 
> Signed-off-by: Pantelis Antoniou <panto@antoniou-consulting.com>


Applied.

Plese consider a follow-up patch to address David's concerns.

Thanks,
jdl

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-01-06 22:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-04 19:12 Fix util_is_printable_string Pantelis Antoniou
2013-01-05 12:49 ` David Gibson
2013-01-06 21:38 ` Jon Loeliger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox