diff options
author | Simon Glass <sjg@chromium.org> | 2021-02-11 12:20:10 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-02-12 22:12:19 +0000 |
commit | 21f58b39ee05903a6d3255476e3a32ea124e4191 (patch) | |
tree | fd65c96d7ef2f15b336c209448bceb9c55b6d29d | |
parent | 0189fc914366562c204e8556a0ac46ef24cc320e (diff) | |
download | chrome-ec-21f58b39ee05903a6d3255476e3a32ea124e4191.tar.gz |
Avoid passing char values to ctype functions
With Zephyr's newlib we get a warning when trying to do this, since it
includes the following note in:
/opt/zephyr-sdk/arm-zephyr-eabi/arm-zephyr-eabi/include/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'."
Presumably this is so characters above ASCII 127 are handled correctly,
even if these are seldom used.
Update the few affected call sites to ensure the value is cast to an
unsigned char so that it will not fall afoul of the newlib warning.
Note that the ECOS version of the ctype functions does not make use of
an array, so does not suffer from failure if negative values are
passed. Still, it is harmless to fix it.
BUG=b:180023514
BRANCH=none
TEST=build zephyr volteer with CONFIG_NEWLIB_LIBC and see no warnings
Signed-off-by: Simon Glass <sjg@chromium.org>
Change-Id: Ieae2fab8c20b75baa46d01dd8cdb393c6bb5c2c2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2691413
Reviewed-by: Keith Short <keithshort@chromium.org>
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
-rw-r--r-- | common/base32.c | 2 | ||||
-rw-r--r-- | common/charger.c | 4 | ||||
-rw-r--r-- | common/console.c | 6 |
3 files changed, 6 insertions, 6 deletions
diff --git a/common/base32.c b/common/base32.c index 8a33d7685c..a6be8409b1 100644 --- a/common/base32.c +++ b/common/base32.c @@ -119,7 +119,7 @@ int base32_decode(uint8_t *dest, int destlen_bits, const char *src, for (; *src; src++) { int sym, sbits, dbits, b; - if (isspace(*src) || *src == '-') + if (isspace((unsigned char)*src) || *src == '-') continue; sym = decode_sym(*src); diff --git a/common/charger.c b/common/charger.c index 4b75d2e5ef..f9fd1c4640 100644 --- a/common/charger.c +++ b/common/charger.c @@ -196,7 +196,7 @@ static int command_charger(int argc, char **argv) return EC_SUCCESS; } - idx_provided = isdigit(argv[1][0]); + idx_provided = isdigit((unsigned char)argv[1][0]); if (idx_provided) chgnum = atoi(argv[1]); else @@ -673,4 +673,4 @@ enum ec_error_list charger_enable_linear_charge(int chgnum, bool enable) enable); return EC_ERROR_UNIMPLEMENTED; -}
\ No newline at end of file +} diff --git a/common/console.c b/common/console.c index 1a2a41c9c1..cf25b40c30 100644 --- a/common/console.c +++ b/common/console.c @@ -93,7 +93,7 @@ static int split_words(char *input, int *argc, char **argv) for (c = input; in_line; c++) { if (!*c) in_line = 0; - if (isspace(*c) || !*c) { + if (isspace((unsigned char)*c) || !*c) { if (in_word) { /* Ending a word */ *c = '\0'; @@ -450,7 +450,7 @@ static int handle_esc(int c) } /* Check if the escape code is done */ - if (isalpha(c) || c == '~') + if (isalpha((unsigned char)c) || c == '~') esc_state = ESC_OUTSIDE; else esc_state = ESC_BAD; @@ -610,7 +610,7 @@ static void console_handle_char(int c) default: /* Ignore non-printing characters */ - if (!isprint(c)) + if (!isprint((unsigned char)c)) break; #ifndef CONFIG_EXPERIMENTAL_CONSOLE |