From ccff1a68e10909fb73e471772d1d603e3fa72297 Mon Sep 17 00:00:00 2001 From: Ali Gholami Rudi Date: Fri, 25 Aug 2017 00:14:41 +0430 Subject: [PATCH] tr: missing casts for isdigit() --- clr.c | 11 ++++++----- eval.c | 4 ++-- tr.c | 8 ++++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/clr.c b/clr.c index 9168399..91ca560 100644 --- a/clr.c +++ b/clr.c @@ -43,16 +43,17 @@ static int ccom(char *s, int len) int clr_get(char *s) { + int c = (unsigned char) s[0]; int i; - if (s[0] == '#' && strlen(s) == 7) + if (c == '#' && strlen(s) == 7) return CLR_RGB(ccom(s + 1, 2), ccom(s + 3, 2), ccom(s + 5, 2)); - if (s[0] == '#' && strlen(s) == 4) + if (c == '#' && strlen(s) == 4) return CLR_RGB(ccom(s + 1, 1), ccom(s + 2, 1), ccom(s + 3, 1)); - if (s[0] == '#' && strlen(s) == 3) + if (c == '#' && strlen(s) == 3) return CLR_RGB(ccom(s + 1, 2), ccom(s + 1, 2), ccom(s + 1, 2)); - if (s[0] == '#' && strlen(s) == 2) + if (c == '#' && strlen(s) == 2) return CLR_RGB(ccom(s + 1, 1), ccom(s + 1, 1), ccom(s + 1, 1)); - if (isdigit(s[0]) && atoi(s) >= 0 && atoi(s) < LEN(colors)) + if (isdigit(c) && atoi(s) >= 0 && atoi(s) < LEN(colors)) return colors[atoi(s)].value; for (i = 0; i < LEN(colors); i++) if (!strcmp(colors[i].name, s)) diff --git a/eval.c b/eval.c index 3cc4b14..7d4b194 100644 --- a/eval.c +++ b/eval.c @@ -37,7 +37,7 @@ static int evalnum(char **_s) char *s = *_s; int n = 0; /* the result */ int mag = 0; /* n should be divided by mag */ - while (isdigit(*s) || *s == '.') { + while (isdigit((unsigned char) *s) || *s == '.') { if (*s == '.') { mag = 1; s++; @@ -66,7 +66,7 @@ static int evaljmp(char **s, int c) static int evalisnum(char **s) { - return **s == '.' || isdigit(**s); + return **s == '.' || isdigit((unsigned char) **s); } static int evalexpr(char **s); diff --git a/tr.c b/tr.c index f2b881e..84e5803 100644 --- a/tr.c +++ b/tr.c @@ -345,7 +345,7 @@ static void tr_ad(char **args) n_na = 0; if (!s) return; - if (isdigit(s[0])) + if (isdigit((unsigned char) s[0])) n_j = atoi(s) & 15; else n_j = s[0] == 'p' ? AD_P | adjmode(s[1], AD_B) : adjmode(s[0], n_j); @@ -631,11 +631,11 @@ static void tr_nm(char **args) n_nm = 1; n_ln = eval_re(args[1], n_ln, 0); n_ln = MAX(0, n_ln); - if (args[2] && isdigit(args[2][0])) + if (args[2] && isdigit((unsigned char) args[2][0])) n_nM = MAX(1, eval(args[2], 0)); - if (args[3] && isdigit(args[3][0])) + if (args[3] && isdigit((unsigned char) args[3][0])) n_nS = MAX(0, eval(args[3], 0)); - if (args[4] && isdigit(args[4][0])) + if (args[4] && isdigit((unsigned char) args[4][0])) n_nI = MAX(0, eval(args[4], 0)); } -- 2.11.4.GIT