From fefa5e0ff5af98d8258987e21422243926ee2b3c Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Tue, 6 Aug 2019 16:54:52 +0200 Subject: *: fix ctype (isalpha & co.) casts The correct cast for these is (unsigned char), because "char" could be signed and thus have some negative value. isalpha & co. expect an int arg that is positive, i.e. 0-255. So we need to cast to (unsigned char) when calling any of these. Signed-off-by: David Lamparter --- tools/coccinelle/ctype_cast.cocci | 11 +++++++++++ tools/start-stop-daemon.c | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tools/coccinelle/ctype_cast.cocci (limited to 'tools') diff --git a/tools/coccinelle/ctype_cast.cocci b/tools/coccinelle/ctype_cast.cocci new file mode 100644 index 000000000..b0b00959d --- /dev/null +++ b/tools/coccinelle/ctype_cast.cocci @@ -0,0 +1,11 @@ + +@@ +identifier func =~ "^(to|is)(alnum|cntrl|print|xdigit|alpha|digit|punct|ascii|graph|space|blank|lower|upper)$"; +expression e; +@@ + + func( +- (int) ++ (unsigned char) + e) + diff --git a/tools/start-stop-daemon.c b/tools/start-stop-daemon.c index 5903f8732..c75306a95 100644 --- a/tools/start-stop-daemon.c +++ b/tools/start-stop-daemon.c @@ -401,7 +401,7 @@ static void parse_schedule_item(const char *string, struct schedule_item *item) if (!strcmp(string, "forever")) { item->type = sched_forever; - } else if (isdigit((int)string[0])) { + } else if (isdigit((unsigned char)string[0])) { item->type = sched_timeout; if (parse_integer(string, &item->value) != 0) badusage("invalid timeout value in schedule"); -- cgit v1.2.3