aboutsummaryrefslogtreecommitdiff
path: root/treesource.c
diff options
context:
space:
mode:
authorSerge Lamikhov-Center <Serge.Lamikhov@gmail.com>2013-12-25 15:26:03 +1100
committerDavid Gibson <david@gibson.dropbear.id.au>2013-12-25 15:27:22 +1100
commit17119ab0a52df5fb30749d038d796d7e78702e3c (patch)
treea61fdaf6e6a46d6999f70ea8c340522a7fb85651 /treesource.c
parent17625371eeea2fa7257361163c52d336a1a98ebc (diff)
downloaddtc-17119ab0a52df5fb30749d038d796d7e78702e3c.zip
dtc-17119ab0a52df5fb30749d038d796d7e78702e3c.tar.gz
dtc-17119ab0a52df5fb30749d038d796d7e78702e3c.tar.bz2
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@gmail.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'treesource.c')
-rw-r--r--treesource.c4
1 files changed, 2 insertions, 2 deletions
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);