linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ppc/xmon: use isxdigit/isspace/isalnum from ctype.h
@ 2014-07-15  7:28 Vincent Bernat
  2014-07-15  8:55 ` David Laight
  0 siblings, 1 reply; 5+ messages in thread
From: Vincent Bernat @ 2014-07-15  7:28 UTC (permalink / raw)
  To: Benjamin Herrenschmidt, Paul Mackerras, linuxppc-dev; +Cc: Vincent Bernat

Use linux/ctype.h instead of defining custom versions of
isxdigit/isspace/isalnum.

Signed-off-by: Vincent Bernat <vincent@bernat.im>
---
 arch/powerpc/xmon/xmon.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index d199bfa2f1fa..c0c31a47c469 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -24,6 +24,7 @@
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/bug.h>
+#include <linux/ctype.h>
 
 #include <asm/ptrace.h>
 #include <asm/string.h>
@@ -177,14 +178,6 @@ extern void xmon_leave(void);
 #define GETWORD(v)	(((v)[0] << 24) + ((v)[1] << 16) + ((v)[2] << 8) + (v)[3])
 #endif
 
-#define isxdigit(c)	(('0' <= (c) && (c) <= '9') \
-			 || ('a' <= (c) && (c) <= 'f') \
-			 || ('A' <= (c) && (c) <= 'F'))
-#define isalnum(c)	(('0' <= (c) && (c) <= '9') \
-			 || ('a' <= (c) && (c) <= 'z') \
-			 || ('A' <= (c) && (c) <= 'Z'))
-#define isspace(c)	(c == ' ' || c == '\t' || c == 10 || c == 13 || c == 0)
-
 static char *help_string = "\
 Commands:\n\
   b	show breakpoints\n\
@@ -2121,9 +2114,6 @@ static void dump_pacas(void)
 }
 #endif
 
-#define isxdigit(c)	(('0' <= (c) && (c) <= '9') \
-			 || ('a' <= (c) && (c) <= 'f') \
-			 || ('A' <= (c) && (c) <= 'F'))
 static void
 dump(void)
 {
-- 
2.0.1

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

* RE: [PATCH] ppc/xmon: use isxdigit/isspace/isalnum from ctype.h
  2014-07-15  7:28 [PATCH] ppc/xmon: use isxdigit/isspace/isalnum from ctype.h Vincent Bernat
@ 2014-07-15  8:55 ` David Laight
  2014-07-15  9:38   ` Vincent Bernat
  0 siblings, 1 reply; 5+ messages in thread
From: David Laight @ 2014-07-15  8:55 UTC (permalink / raw)
  To: 'Vincent Bernat', Benjamin Herrenschmidt, Paul Mackerras,
	linuxppc-dev@lists.ozlabs.org

RnJvbTogVmluY2VudCBCZXJuYXQNCj4gVXNlIGxpbnV4L2N0eXBlLmggaW5zdGVhZCBvZiBkZWZp
bmluZyBjdXN0b20gdmVyc2lvbnMgb2YNCj4gaXN4ZGlnaXQvaXNzcGFjZS9pc2FsbnVtLg0KDQou
Li4NCj4gLSNkZWZpbmUgaXNzcGFjZShjKQkoYyA9PSAnICcgfHwgYyA9PSAnXHQnIHx8IGMgPT0g
MTAgfHwgYyA9PSAxMyB8fCBjID09IDApDQoNClRoYXQgaXMgZGlmZmVyZW50IGZyb20gdGhlIHZl
cnNpb24gaW4gbGludXgvY3R5cGUuaA0KRXNwZWNpYWxseSBmb3IgJ2MgPT0gMCcsIGJ1dCBwcm9i
YWJseSBhbHNvIHZlcnRpY2FsIHRhYiBhbmQgZm9ybSBmZWVkLg0KDQoJRGF2aWQNCg0K

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

* Re: [PATCH] ppc/xmon: use isxdigit/isspace/isalnum from ctype.h
  2014-07-15  8:55 ` David Laight
@ 2014-07-15  9:38   ` Vincent Bernat
  2014-07-15 11:43     ` [PATCH] ppc/xmon: use isspace/isxdigit/isalnum from linux/ctype.h Vincent Bernat
  0 siblings, 1 reply; 5+ messages in thread
From: Vincent Bernat @ 2014-07-15  9:38 UTC (permalink / raw)
  To: David Laight; +Cc: Paul Mackerras, linuxppc-dev@lists.ozlabs.org

 =E2=9D=A6 15 juillet 2014 08:55 GMT, David Laight <David.Laight@ACULAB.COM=
>=C2=A0:

>> Use linux/ctype.h instead of defining custom versions of
>> isxdigit/isspace/isalnum.
>
> ...
>> -#define isspace(c)	(c =3D=3D ' ' || c =3D=3D '\t' || c =3D=3D 10 || c =
=3D=3D 13 || c =3D=3D 0)
>
> That is different from the version in linux/ctype.h
> Especially for 'c =3D=3D 0', but probably also vertical tab and form feed.

OK. Looking more carefully, the one in ctype.h is 9-13 (11 is vertical
tab, 12 is form feed), 32 and 160 (non-breaking space, not ASCII).

For isxdigit, this is the same. For isalnum, the one in ctype.h does
accept non ASCII chars from 223.

Also, in xmon.c, isxdigit is defined twice.
--=20
Parenthesise to avoid ambiguity.
            - The Elements of Programming Style (Kernighan & Plauger)

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

* [PATCH] ppc/xmon: use isspace/isxdigit/isalnum from linux/ctype.h
  2014-07-15  9:38   ` Vincent Bernat
@ 2014-07-15 11:43     ` Vincent Bernat
  2014-07-15 23:46       ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 5+ messages in thread
From: Vincent Bernat @ 2014-07-15 11:43 UTC (permalink / raw)
  To: David Laight, Benjamin Herrenschmidt, Paul Mackerras,
	linuxppc-dev@lists.ozlabs.org
  Cc: Vincent Bernat

isxdigit() macro definition is the same.

isalnum() from linux/ctype.h will accept additional latin non-ASCII
characters. This is harmless since this macro is used in scanhex() which
parses user input.

isspace() from linux/ctype.h will accept vertical tab and form feed but
not NULL. The use of this macro is modified to accept NULL as
well. Additional characters are harmless since this macro is also only
used in scanhex().

Signed-off-by: Vincent Bernat <vincent@bernat.im>
---
 arch/powerpc/xmon/xmon.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index d199bfa2f1fa..55d9b48774b7 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -24,6 +24,7 @@
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/bug.h>
+#include <linux/ctype.h>
 
 #include <asm/ptrace.h>
 #include <asm/string.h>
@@ -177,14 +178,6 @@ extern void xmon_leave(void);
 #define GETWORD(v)	(((v)[0] << 24) + ((v)[1] << 16) + ((v)[2] << 8) + (v)[3])
 #endif
 
-#define isxdigit(c)	(('0' <= (c) && (c) <= '9') \
-			 || ('a' <= (c) && (c) <= 'f') \
-			 || ('A' <= (c) && (c) <= 'F'))
-#define isalnum(c)	(('0' <= (c) && (c) <= '9') \
-			 || ('a' <= (c) && (c) <= 'z') \
-			 || ('A' <= (c) && (c) <= 'Z'))
-#define isspace(c)	(c == ' ' || c == '\t' || c == 10 || c == 13 || c == 0)
-
 static char *help_string = "\
 Commands:\n\
   b	show breakpoints\n\
@@ -2121,9 +2114,6 @@ static void dump_pacas(void)
 }
 #endif
 
-#define isxdigit(c)	(('0' <= (c) && (c) <= '9') \
-			 || ('a' <= (c) && (c) <= 'f') \
-			 || ('A' <= (c) && (c) <= 'F'))
 static void
 dump(void)
 {
@@ -2526,7 +2516,7 @@ scanhex(unsigned long *vp)
 		int i;
 		for (i=0; i<63; i++) {
 			c = inchar();
-			if (isspace(c)) {
+			if (isspace(c) || c == '\0') {
 				termch = c;
 				break;
 			}
-- 
2.0.1

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

* Re: [PATCH] ppc/xmon: use isspace/isxdigit/isalnum from linux/ctype.h
  2014-07-15 11:43     ` [PATCH] ppc/xmon: use isspace/isxdigit/isalnum from linux/ctype.h Vincent Bernat
@ 2014-07-15 23:46       ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 5+ messages in thread
From: Benjamin Herrenschmidt @ 2014-07-15 23:46 UTC (permalink / raw)
  To: Vincent Bernat
  Cc: linuxppc-dev@lists.ozlabs.org, David Laight, Paul Mackerras

On Tue, 2014-07-15 at 13:43 +0200, Vincent Bernat wrote:
> isxdigit() macro definition is the same.
> 
> isalnum() from linux/ctype.h will accept additional latin non-ASCII
> characters. This is harmless since this macro is used in scanhex() which
> parses user input.
> 
> isspace() from linux/ctype.h will accept vertical tab and form feed but
> not NULL. The use of this macro is modified to accept NULL as
> well. Additional characters are harmless since this macro is also only
> used in scanhex().

I don't think we care about \0 ... Paul, care to chime in ? After all,
you wrote that stuff a century or two ago... :)

Cheers,
Ben.

> Signed-off-by: Vincent Bernat <vincent@bernat.im>
> ---
>  arch/powerpc/xmon/xmon.c | 14 ++------------
>  1 file changed, 2 insertions(+), 12 deletions(-)
> 
> diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
> index d199bfa2f1fa..55d9b48774b7 100644
> --- a/arch/powerpc/xmon/xmon.c
> +++ b/arch/powerpc/xmon/xmon.c
> @@ -24,6 +24,7 @@
>  #include <linux/interrupt.h>
>  #include <linux/irq.h>
>  #include <linux/bug.h>
> +#include <linux/ctype.h>
>  
>  #include <asm/ptrace.h>
>  #include <asm/string.h>
> @@ -177,14 +178,6 @@ extern void xmon_leave(void);
>  #define GETWORD(v)	(((v)[0] << 24) + ((v)[1] << 16) + ((v)[2] << 8) + (v)[3])
>  #endif
>  
> -#define isxdigit(c)	(('0' <= (c) && (c) <= '9') \
> -			 || ('a' <= (c) && (c) <= 'f') \
> -			 || ('A' <= (c) && (c) <= 'F'))
> -#define isalnum(c)	(('0' <= (c) && (c) <= '9') \
> -			 || ('a' <= (c) && (c) <= 'z') \
> -			 || ('A' <= (c) && (c) <= 'Z'))
> -#define isspace(c)	(c == ' ' || c == '\t' || c == 10 || c == 13 || c == 0)
> -
>  static char *help_string = "\
>  Commands:\n\
>    b	show breakpoints\n\
> @@ -2121,9 +2114,6 @@ static void dump_pacas(void)
>  }
>  #endif
>  
> -#define isxdigit(c)	(('0' <= (c) && (c) <= '9') \
> -			 || ('a' <= (c) && (c) <= 'f') \
> -			 || ('A' <= (c) && (c) <= 'F'))
>  static void
>  dump(void)
>  {
> @@ -2526,7 +2516,7 @@ scanhex(unsigned long *vp)
>  		int i;
>  		for (i=0; i<63; i++) {
>  			c = inchar();
> -			if (isspace(c)) {
> +			if (isspace(c) || c == '\0') {
>  				termch = c;
>  				break;
>  			}

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

end of thread, other threads:[~2014-07-15 23:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-15  7:28 [PATCH] ppc/xmon: use isxdigit/isspace/isalnum from ctype.h Vincent Bernat
2014-07-15  8:55 ` David Laight
2014-07-15  9:38   ` Vincent Bernat
2014-07-15 11:43     ` [PATCH] ppc/xmon: use isspace/isxdigit/isalnum from linux/ctype.h Vincent Bernat
2014-07-15 23:46       ` Benjamin Herrenschmidt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).