From f8e9323ecbc21aaca893b30e8bfe7f8ec768f3b6 Mon Sep 17 00:00:00 2001 From: David Given Date: Tue, 17 Mar 2015 21:20:27 +0100 Subject: [PATCH] C spec requires the ctype functions to be valid for unsigned chars, so casting to char is invalid. We cast to uint8_t instead. Bonus: smaller code! --HG-- extra : source : b75c83c0539dd462bee151beab76938eca046294 --- Library/libs/isalnum.c | 1 + Library/libs/isalpha.c | 1 + Library/libs/isascii.c | 4 +++- Library/libs/iscntrl.c | 3 ++- Library/libs/isdigit.c | 3 ++- Library/libs/isgraph.c | 1 + Library/libs/islower.c | 3 ++- Library/libs/isoctal.c | 3 ++- Library/libs/ispunct.c | 1 + Library/libs/isspace.c | 1 + Library/libs/isupper.c | 3 ++- Library/libs/isxdigit.c | 3 ++- 12 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Library/libs/isalnum.c b/Library/libs/isalnum.c index e3d2cf0b..511038d7 100644 --- a/Library/libs/isalnum.c +++ b/Library/libs/isalnum.c @@ -1,3 +1,4 @@ +#include #include int isalnum(int c) diff --git a/Library/libs/isalpha.c b/Library/libs/isalpha.c index 0980d09b..07208ced 100644 --- a/Library/libs/isalpha.c +++ b/Library/libs/isalpha.c @@ -1,3 +1,4 @@ +#include #include int isalpha(int c) diff --git a/Library/libs/isascii.c b/Library/libs/isascii.c index b4278f0c..2bc38054 100644 --- a/Library/libs/isascii.c +++ b/Library/libs/isascii.c @@ -1,7 +1,9 @@ +#include #include int isascii(int c) { - return (c >= 0) && (c <= 127); + uint8_t cb = c; + return (cb >= 0) && (cb <= 127); } diff --git a/Library/libs/iscntrl.c b/Library/libs/iscntrl.c index 4d770e98..a0f7d303 100644 --- a/Library/libs/iscntrl.c +++ b/Library/libs/iscntrl.c @@ -1,7 +1,8 @@ +#include #include int iscntrl(int c) { - char bc = c; + uint8_t bc = c; return ((bc >= 0) && (bc <= 31)) || (bc == 127); } diff --git a/Library/libs/isdigit.c b/Library/libs/isdigit.c index 7a3a2a9d..669bb28b 100644 --- a/Library/libs/isdigit.c +++ b/Library/libs/isdigit.c @@ -1,8 +1,9 @@ +#include #include int isdigit(int c) { - char bc = c; + uint8_t bc = c; return (bc >= '0') && (bc <= '9'); } diff --git a/Library/libs/isgraph.c b/Library/libs/isgraph.c index d5660132..fdc776e2 100644 --- a/Library/libs/isgraph.c +++ b/Library/libs/isgraph.c @@ -1,3 +1,4 @@ +#include #include int isgraph(int c) diff --git a/Library/libs/islower.c b/Library/libs/islower.c index b63fce04..ba78d10d 100644 --- a/Library/libs/islower.c +++ b/Library/libs/islower.c @@ -1,7 +1,8 @@ +#include #include int islower(int c) { - char bc = c; + uint8_t bc = c; return (bc >= 'a') && (bc <= 'z'); } diff --git a/Library/libs/isoctal.c b/Library/libs/isoctal.c index 3d69a064..a1a86225 100644 --- a/Library/libs/isoctal.c +++ b/Library/libs/isoctal.c @@ -1,8 +1,9 @@ +#include #include int isoctal(int c) { - char bc = c; + uint8_t bc = c; return (bc >= '0') && (bc <= '7'); } diff --git a/Library/libs/ispunct.c b/Library/libs/ispunct.c index be72ef87..2c88fa49 100644 --- a/Library/libs/ispunct.c +++ b/Library/libs/ispunct.c @@ -1,3 +1,4 @@ +#include #include int ispunct(int c) diff --git a/Library/libs/isspace.c b/Library/libs/isspace.c index 6cba2db5..8cadeb5d 100644 --- a/Library/libs/isspace.c +++ b/Library/libs/isspace.c @@ -1,3 +1,4 @@ +#include #include #include diff --git a/Library/libs/isupper.c b/Library/libs/isupper.c index d2d3dd81..0dad20dc 100644 --- a/Library/libs/isupper.c +++ b/Library/libs/isupper.c @@ -1,7 +1,8 @@ +#include #include int isupper(int c) { - char bc = c; + uint8_t bc = c; return (bc >= 'A') && (bc <= 'Z'); } diff --git a/Library/libs/isxdigit.c b/Library/libs/isxdigit.c index 3da08f32..483e64b8 100644 --- a/Library/libs/isxdigit.c +++ b/Library/libs/isxdigit.c @@ -1,8 +1,9 @@ +#include #include int isxdigit(int c) { - char bc = c; + uint8_t bc = c; return isdigit(bc) || ((bc >= 'a') && (bc <= 'f')) || ((bc >= 'A') && (bc <= 'F')); -- 2.34.1