summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2022-07-15 12:57:10 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-07-16 00:13:20 +0000
commitc23d2848ac11829a22bb60533ffc5572de573262 (patch)
treec25fa5d6daf2ed3df3cc368e8632dc1d6d46181c /common
parentb680d4103a842eb1d92b0ba1a7f6a7362b3c9a6c (diff)
downloadchrome-ec-c23d2848ac11829a22bb60533ffc5572de573262.tar.gz
common/util: Add casts
When compiling against the standard library, clang complains: common/util.c:66:6: error: array subscript is of type 'char' [-Werror,-Wchar-subscripts] tolower(*s) == 'f' || tolower(*s) == 'n') { ^~~~~~~~~~~ According to POSIX: The tolower() and tolower_l() functions have as a domain a type int, the value of which is representable as an unsigned char or the value of EOF. If the argument has any other value, the behavior is undefined. https://pubs.opengroup.org/onlinepubs/9699919799/functions/tolower.html BRANCH=none BUG=b:234181908 TEST=make utils-str Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I84f4bfb647f29b24b1c3bd7f5d222275354c4698 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3765458 Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/util.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/common/util.c b/common/util.c
index c911a83ce9..c89770f161 100644
--- a/common/util.c
+++ b/common/util.c
@@ -63,14 +63,16 @@ int parse_bool(const char *s, int *dest)
{
/* off, disable, false, no */
if (!strcasecmp(s, "off") || !strncasecmp(s, "dis", 3) ||
- tolower(*s) == 'f' || tolower(*s) == 'n') {
+ tolower((unsigned char)*s) == 'f' ||
+ tolower((unsigned char)*s) == 'n') {
*dest = 0;
return 1;
}
/* on, enable, true, yes */
if (!strcasecmp(s, "on") || !strncasecmp(s, "ena", 3) ||
- tolower(*s) == 't' || tolower(*s) == 'y') {
+ tolower((unsigned char)*s) == 't' ||
+ tolower((unsigned char)*s) == 'y') {
*dest = 1;
return 1;
}