[Crosstoolchain-logs] [device-tree-compiler] 104/198: Pass 'unsigned char' type to isdigit()/isspace()/isprint() functions

Hector Oron zumbi at moszumanska.debian.org
Thu Dec 8 17:06:58 UTC 2016


This is an automated email from the git hooks/post-receive script.

zumbi pushed a commit to branch upstream/1.4.x
in repository device-tree-compiler.

commit 17119ab0a52df5fb30749d038d796d7e78702e3c
Author: Serge Lamikhov-Center <Serge.Lamikhov at gmail.com>
Date:   Wed Dec 25 15:26:03 2013 +1100

    Pass 'unsigned char' type to isdigit()/isspace()/isprint() functions
    
    The isdigit(), isprint(), etc. functions take an int, whose value is
    required to be in the range of an _unsigned_ char, or EOF.  This, horribly,
    means that systems which have a signed char by default need casts to pass
    a char variable safely to these functions.
    
    We can't do this more nicely by making the variables themselves 'unsigned
    char *' because then we'll get warnings passing them to the strchr() etc.
    functions.
    
    At least the cygwin version of these functions, are designed to generate
    warnings if this isn't done, as explained by this comment from ctype.h:
       These macros are intentionally written in a manner that will trigger
       a gcc -Wall warning if the user mistakenly passes a 'char' instead
       of an int containing an 'unsigned char'.
    
    Signed-off-by: Serge Lamikhov-Center <Serge.Lamikhov at gmail.com>
    Signed-off-by: David Gibson <david at gibson.dropbear.id.au>
---
 dtc-lexer.l  | 4 ++--
 treesource.c | 4 ++--
 util.c       | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/dtc-lexer.l b/dtc-lexer.l
index 369407a..0cd7e67 100644
--- a/dtc-lexer.l
+++ b/dtc-lexer.l
@@ -75,11 +75,11 @@ static bool pop_input_file(void);
 			char *line, *tmp, *fn;
 			/* skip text before line # */
 			line = yytext;
-			while (!isdigit(*line))
+			while (!isdigit((unsigned char)*line))
 				line++;
 			/* skip digits in line # */
 			tmp = line;
-			while (!isspace(*tmp))
+			while (!isspace((unsigned char)*tmp))
 				tmp++;
 			/* "NULL"-terminate line # */
 			*tmp = '\0';
diff --git a/treesource.c b/treesource.c
index ffebb77..bf7a626 100644
--- a/treesource.c
+++ b/treesource.c
@@ -56,7 +56,7 @@ static void write_prefix(FILE *f, int level)
 
 static bool isstring(char c)
 {
-	return (isprint(c)
+	return (isprint((unsigned char)c)
 		|| (c == '\0')
 		|| strchr("\a\b\t\n\v\f\r", c));
 }
@@ -119,7 +119,7 @@ static void write_propval_string(FILE *f, struct data val)
 			fprintf(f, "\"");
 			break;
 		default:
-			if (isprint(c))
+			if (isprint((unsigned char)c))
 				fprintf(f, "%c", c);
 			else
 				fprintf(f, "\\x%02hhx", c);
diff --git a/util.c b/util.c
index 2347af9..330b594 100644
--- a/util.c
+++ b/util.c
@@ -87,7 +87,7 @@ bool util_is_printable_string(const void *data, int len)
 
 	while (s < se) {
 		ss = s;
-		while (s < se && *s && isprint(*s))
+		while (s < se && *s && isprint((unsigned char)*s))
 			s++;
 
 		/* not zero, or not done yet */

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/crosstoolchain/device-tree-compiler.git



More information about the Crosstoolchain-logs mailing list