From 4dfd247a0b36b501c21d95b5a6506cceead22924 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Thu, 2 Dec 2021 17:28:53 -0800 Subject: [PATCH] [nfc] cast inputs to ctype.h 'is*' functions The ctype.h `is*` functions are typically implemented as macros using a lookup table. This is fine, but on Cygwin the compiler is somewhat picky about this: lib/ast/fmtesc.c:116:59: warning: array subscript has type char [-Wchar-subscripts] 116 | (c == '#' && (b == f || isspace(*(b - 1))) | ^~~~~~~~ This change squashes these warnings. --- cmd/tools/ccomps.c | 4 ++-- cmd/tools/colxlate.c | 2 +- cmd/tools/graphml2gv.c | 2 +- cmd/tools/gv2gml.c | 4 ++-- cmd/tools/gxl2gv.c | 2 +- lib/ast/fmtesc.c | 2 +- lib/ast/strmatch.c | 2 +- lib/cgraph/write.c | 2 +- lib/common/args.c | 2 +- lib/common/emit.c | 6 +++--- lib/common/utils.c | 2 +- lib/common/xml.c | 4 ++-- lib/expr/excontext.c | 4 ++-- lib/expr/exeval.c | 14 +++++++------- lib/expr/exparse.y | 2 +- lib/expr/extoken.c | 2 +- lib/fdpgen/xlayout.c | 2 +- lib/gvc/gvconfig.c | 8 ++++---- lib/gvc/gvdevice.c | 2 +- lib/gvpr/gvpr.c | 2 +- lib/neatogen/adjust.c | 2 +- lib/neatogen/neatoinit.c | 2 +- lib/sfdpgen/sfdpinit.c | 8 ++++---- lib/sfio/sftable.c | 6 +++--- lib/sfio/sfvprintf.c | 12 ++++++------ lib/sfio/sfvscanf.c | 6 +++--- lib/xdot/xdot.c | 2 +- 27 files changed, 54 insertions(+), 54 deletions(-) diff --git a/cmd/tools/ccomps.c b/cmd/tools/ccomps.c index ad1afda11..fd54de156 100644 --- a/cmd/tools/ccomps.c +++ b/cmd/tools/ccomps.c @@ -188,12 +188,12 @@ static void init(int argc, char *argv[]) char *p = optarg + 1; if (*optarg == '#') x_mode = BY_INDEX; else x_mode = BY_SIZE; - if (isdigit(*p)) { + if (isdigit((int)*p)) { x_index = (int)strtol (p, &endp, 10); printMode = EXTRACT; if (*endp == '-') { p = endp + 1; - if (isdigit(*p)) { + if (isdigit((int)*p)) { x_final = atoi (p); if (x_final < x_index) { printMode = INTERNAL; diff --git a/cmd/tools/colxlate.c b/cmd/tools/colxlate.c index 4c40ac4b1..f01b33faf 100644 --- a/cmd/tools/colxlate.c +++ b/cmd/tools/colxlate.c @@ -59,7 +59,7 @@ char *colorxlate(char *str, char *buf) sizeof(fake), colorcmpf); } if (last == NULL) { - if (!isdigit(canon[0])) { + if (!isdigit((int)canon[0])) { fprintf(stderr, "warning: %s is not a known color\n", str); strcpy(buf, str); } else diff --git a/cmd/tools/graphml2gv.c b/cmd/tools/graphml2gv.c index c4456f3cb..21c8be7e3 100644 --- a/cmd/tools/graphml2gv.c +++ b/cmd/tools/graphml2gv.c @@ -203,7 +203,7 @@ static int isAnonGraph(char *name) { if (*name++ != '%') return 0; - while (isdigit(*name)) + while (isdigit((int)*name)) name++; /* skip over digits */ return (*name == '\0'); } diff --git a/cmd/tools/gv2gml.c b/cmd/tools/gv2gml.c index ad274e65a..e4a0a856c 100644 --- a/cmd/tools/gv2gml.c +++ b/cmd/tools/gv2gml.c @@ -102,7 +102,7 @@ isNumber (char* s) char* ep = s; strtod(s, &ep); if (s != ep) { - while (*ep && isspace(*ep)) ep++; + while (*ep && isspace((int)*ep)) ep++; if (*ep) return 0; else return 1; } @@ -158,7 +158,7 @@ emitPoint (double x, double y, FILE* outFile, int ix) static char* skipWS (char* s) { - while (isspace(*s)) s++; + while (isspace((int)*s)) s++; return s; } diff --git a/cmd/tools/gxl2gv.c b/cmd/tools/gxl2gv.c index 9adae44d6..18abeef22 100644 --- a/cmd/tools/gxl2gv.c +++ b/cmd/tools/gxl2gv.c @@ -218,7 +218,7 @@ static int isAnonGraph(char *name) { if (*name++ != '%') return 0; - while (isdigit(*name)) + while (isdigit((int)*name)) name++; /* skip over digits */ return (*name == '\0'); } diff --git a/lib/ast/fmtesc.c b/lib/ast/fmtesc.c index 4affb3c52..d94c6a518 100644 --- a/lib/ast/fmtesc.c +++ b/lib/ast/fmtesc.c @@ -113,7 +113,7 @@ char *fmtquote(const char *as, const char *qb, const char *qe, size_t n, (isspace(c) || (((flags & FMT_SHELL) || shell) && (strchr("\";~&|()<>[]*?", c) || - (c == '#' && (b == f || isspace(*(b - 1))) + (c == '#' && (b == f || isspace((int)*(b - 1))) ) ) ) diff --git a/lib/ast/strmatch.c b/lib/ast/strmatch.c index 362d06030..d58edccab 100644 --- a/lib/ast/strmatch.c +++ b/lib/ast/strmatch.c @@ -449,7 +449,7 @@ onematch(Match_t * mp, int g, char *s, char *p, char *e, char *r, (void)mbgetchar(p); range = oldp; } else - if ((isalpha(*oldp) && isalpha(*olds) + if ((isalpha((int)*oldp) && isalpha((int)*olds) && tolower(*oldp) == tolower(*olds)) || sc == mbgetchar(oldp)) ok = 1; diff --git a/lib/cgraph/write.c b/lib/cgraph/write.c index 2aea82550..d6cd8b23b 100644 --- a/lib/cgraph/write.c +++ b/lib/cgraph/write.c @@ -657,7 +657,7 @@ int agwrite(Agraph_t * g, void *ofile) char* s; int len; Level = 0; /* re-initialize tab level */ - if ((s = agget(g, "linelength")) && isdigit(*s)) { + if ((s = agget(g, "linelength")) && isdigit((int)*s)) { len = (int)strtol(s, (char **)NULL, 10); if (len == 0 || len >= MIN_OUTPUTLINE) Max_outputline = len; diff --git a/lib/common/args.c b/lib/common/args.c index 9f8ee70fa..803d6bc8b 100644 --- a/lib/common/args.c +++ b/lib/common/args.c @@ -127,7 +127,7 @@ config_extra_args(GVC_t *gvc, int argc, char** argv) switch (arg[1]) { case 'v': gvc->common.verbose = 1; - if (isdigit(arg[2])) + if (isdigit((int)arg[2])) gvc->common.verbose = atoi(&arg[2]); break; case 'O' : diff --git a/lib/common/emit.c b/lib/common/emit.c index 3c76ac805..0488d9630 100644 --- a/lib/common/emit.c +++ b/lib/common/emit.c @@ -1014,7 +1014,7 @@ static bool is_natural_number(const char *sstr) const char *str = sstr; while (*str) - if (!isdigit(*str++)) + if (!isdigit((int)*str++)) return false; return true; } @@ -1995,7 +1995,7 @@ static void emit_attachment(GVJ_t * job, textlabel_t * lp, splines * spl) const char *s; for (s = lp->text; *s; s++) { - if (!isspace(*s)) + if (!isspace((int)*s)) break; } if (*s == '\0') @@ -3770,7 +3770,7 @@ static int style_token(char **s, agxbuf * xb) int token; char c; - while (*p && (isspace(*p) || *p == ',')) + while (*p && (isspace((int)*p) || *p == ',')) p++; switch (*p) { case '\0': diff --git a/lib/common/utils.c b/lib/common/utils.c index 3cfb95c0c..929eb3554 100644 --- a/lib/common/utils.c +++ b/lib/common/utils.c @@ -454,7 +454,7 @@ boolean mapBool(char *p, boolean dflt) return TRUE; if (!strcasecmp(p, "yes")) return TRUE; - if (isdigit(*p)) + if (isdigit((int)*p)) return atoi(p); else return dflt; diff --git a/lib/common/xml.c b/lib/common/xml.c index abedd0561..000d7471c 100644 --- a/lib/common/xml.c +++ b/lib/common/xml.c @@ -22,10 +22,10 @@ static bool xml_isentity(const char *s) s++; if (*s == 'x' || *s == 'X') { s++; - while (isxdigit(*s)) + while (isxdigit((int)*s)) s++; } else { - while (isdigit(*s)) + while (isdigit((int)*s)) s++; } } else { diff --git a/lib/expr/excontext.c b/lib/expr/excontext.c index d667ed387..31a0e47af 100644 --- a/lib/expr/excontext.c +++ b/lib/expr/excontext.c @@ -36,7 +36,7 @@ excontext(Expr_t* p, char* buf, int n) if (p->linewrap) { t = p->linep + 1; - while (t < &p->line[sizeof(p->line)] && isspace(*t)) + while (t < &p->line[sizeof(p->line)] && isspace((int)*t)) t++; if ((n = (sizeof(p->line) - (t - (p->linep + 1))) - (e - s)) > 0) { @@ -50,7 +50,7 @@ excontext(Expr_t* p, char* buf, int n) t = p->line; if (p->linewrap) p->linewrap = 0; - else while (t < p->linep && isspace(*t)) + else while (t < p->linep && isspace((int)*t)) t++; if ((n = (p->linep - t) - (e - s)) > 0) t += n; diff --git a/lib/expr/exeval.c b/lib/expr/exeval.c index 92557f686..b01335b34 100644 --- a/lib/expr/exeval.c +++ b/lib/expr/exeval.c @@ -301,36 +301,36 @@ prformat(void* vp, Sffmt_t* dp) { if (streqn(txt, "identifier", txt_len)) { - if (*s && !isalpha(*s)) + if (*s && !isalpha((int)*s)) *s++ = '_'; for (; *s; s++) - if (!isalnum(*s)) + if (!isalnum((int)*s)) *s = '_'; } else if (streqn(txt, "invert", txt_len)) { for (; *s; s++) - if (isupper(*s)) + if (isupper((int)*s)) *s = (char)tolower(*s); - else if (islower(*s)) + else if (islower((int)*s)) *s = (char)toupper(*s); } else if (streqn(txt, "lower", txt_len)) { for (; *s; s++) - if (isupper(*s)) + if (isupper((int)*s)) *s = (char)tolower(*s); } else if (streqn(txt, "upper", txt_len)) { for (; *s; s++) - if (islower(*s)) + if (islower((int)*s)) *s = (char)toupper(*s); } else if (streqn(txt, "variable", txt_len)) { for (; *s; s++) - if (!isalnum(*s) && *s != '_') + if (!isalnum((int)*s) && *s != '_') *s = '.'; } } diff --git a/lib/expr/exparse.y b/lib/expr/exparse.y index 796376d1e..3feeec6af 100644 --- a/lib/expr/exparse.y +++ b/lib/expr/exparse.y @@ -1306,7 +1306,7 @@ const char *exop(size_t index) { { size_t k; for (k = 0; yytname[i][k] != '\0'; ++k) { - if (yytname[i][k] != '_' && !isalnum(yytname[i][k])) { + if (yytname[i][k] != '_' && !isalnum((int)yytname[i][k])) { break; } } diff --git a/lib/expr/extoken.c b/lib/expr/extoken.c index f5fa49e2d..2764fd3e9 100644 --- a/lib/expr/extoken.c +++ b/lib/expr/extoken.c @@ -463,7 +463,7 @@ extoken_fn(Expr_t* ex) if (!ex->linewrap && !(ex->disc->flags & EX_PURE)) { s = ex->linep - 1; - while (s > ex->line && isspace(*(s - 1))) + while (s > ex->line && isspace((int)*(s - 1))) s--; if (s == ex->line) { diff --git a/lib/fdpgen/xlayout.c b/lib/fdpgen/xlayout.c index fd8035d0b..0d76403b8 100644 --- a/lib/fdpgen/xlayout.c +++ b/lib/fdpgen/xlayout.c @@ -527,7 +527,7 @@ void fdp_xLayout(graph_t * g, xparams * xpms) ovlp = DFLT_overlap; } /* look for optional ":" or "number:" */ - if ((cp = strchr(ovlp, ':')) && (cp == ovlp || isdigit(*ovlp))) { + if ((cp = strchr(ovlp, ':')) && (cp == ovlp || isdigit((int)*ovlp))) { cp++; rest = cp; tries = atoi (ovlp); diff --git a/lib/gvc/gvconfig.c b/lib/gvc/gvconfig.c index 2d86321fb..1d73b5bb5 100644 --- a/lib/gvc/gvconfig.c +++ b/lib/gvc/gvconfig.c @@ -429,10 +429,10 @@ static bool is_plugin(const char *filepath) { #else // does this filename have a version? - if (len == 0 || !isdigit(filepath[len - 1])) { + if (len == 0 || !isdigit((int)filepath[len - 1])) { return false; } - while (len > 0 && isdigit(filepath[len - 1])) { + while (len > 0 && isdigit((int)filepath[len - 1])) { --len; } @@ -444,11 +444,11 @@ static bool is_plugin(const char *filepath) { return false; } #elif defined(__MINGW32__) || defined(__CYGWIN__) - if (len < 2 || isdigit(filepath[len - 2]) || filepath[len - 1] != '-') { + if (len < 2 || isdigit((int)filepath[len - 2]) || filepath[len - 1] != '-') { return false; } #elif defined(_WIN32) - if (len < 1 || isdigit(filepath[len - 1])) { + if (len < 1 || isdigit((int)filepath[len - 1])) { return false; } #elif ((defined(__hpux__) || defined(__hpux)) && !(defined(__ia64))) diff --git a/lib/gvc/gvdevice.c b/lib/gvc/gvdevice.c index 40fce3c57..0352baeb5 100644 --- a/lib/gvc/gvdevice.c +++ b/lib/gvc/gvdevice.c @@ -545,7 +545,7 @@ static void gv_trim_zeros(char* buf) } // check this really is the result of %.02f printing - assert(isdigit(dotp[1]) && isdigit(dotp[2]) && dotp[3] == '\0'); + assert(isdigit((int)dotp[1]) && isdigit((int)dotp[2]) && dotp[3] == '\0'); if (dotp[2] == '0') { if (dotp[1] == '0') { diff --git a/lib/gvpr/gvpr.c b/lib/gvpr/gvpr.c index bba402c38..4a5379235 100644 --- a/lib/gvpr/gvpr.c +++ b/lib/gvpr/gvpr.c @@ -106,7 +106,7 @@ static char *gettok(char **sp) char c; char q = '\0'; /* if non-0, in quote mode with quote char q */ - while (isspace(*rs)) + while (isspace((int)*rs)) rs++; if ((c = *rs) == '\0') return NULL; diff --git a/lib/neatogen/adjust.c b/lib/neatogen/adjust.c index 29d09c6bc..be3729301 100644 --- a/lib/neatogen/adjust.c +++ b/lib/neatogen/adjust.c @@ -1198,7 +1198,7 @@ parseFactor (char* s, expand_t* pp, float sepfact, float dflt) int i; float x, y; - while (isspace(*s)) s++; + while (isspace((int)*s)) s++; if (*s == '+') { s++; pp->doAdd = 1; diff --git a/lib/neatogen/neatoinit.c b/lib/neatogen/neatoinit.c index bf1f28da3..d14ecde6c 100644 --- a/lib/neatogen/neatoinit.c +++ b/lib/neatogen/neatoinit.c @@ -317,7 +317,7 @@ static int user_spline(attrsym_t * E_pos, edge_t * e) pp++; n--; } - while (isspace(*pos)) pos++; + while (isspace((int)*pos)) pos++; if (*pos == '\0') more = 0; else diff --git a/lib/sfdpgen/sfdpinit.c b/lib/sfdpgen/sfdpinit.c index 71a28f0e1..d9284b9b2 100644 --- a/lib/sfdpgen/sfdpinit.c +++ b/lib/sfdpgen/sfdpinit.c @@ -163,7 +163,7 @@ late_smooth (graph_t* g, Agsym_t* sym, int dflt) if (!sym) return dflt; s = agxget (g, sym); - if (isdigit(*s)) { + if (isdigit((int)*s)) { #if (defined(HAVE_GTS) || defined(HAVE_TRIANGLE)) if ((v = atoi (s)) <= SMOOTHING_RNG) #else @@ -173,7 +173,7 @@ late_smooth (graph_t* g, Agsym_t* sym, int dflt) else rv = dflt; } - else if (isalpha(*s)) { + else if (isalpha((int)*s)) { if (!strcasecmp(s, "avg_dist")) rv = SMOOTHING_STRESS_MAJORIZATION_AVG_DIST; else if (!strcasecmp(s, "graph_dist")) @@ -209,13 +209,13 @@ late_quadtree_scheme (graph_t* g, Agsym_t* sym, int dflt) if (!sym) return dflt; s = agxget (g, sym); - if (isdigit(*s)) { + if (isdigit((int)*s)) { if ((v = atoi (s)) <= QUAD_TREE_FAST && v >= QUAD_TREE_NONE){ rv = v; } else { rv = dflt; } - } else if (isalpha(*s)) { + } else if (isalpha((int)*s)) { if (!strcasecmp(s, "none") || !strcasecmp(s, "false") ){ rv = QUAD_TREE_NONE; } else if (!strcasecmp(s, "normal") || !strcasecmp(s, "true") || !strcasecmp(s, "yes")){ diff --git a/lib/sfio/sftable.c b/lib/sfio/sftable.c index c1800005f..85e446742 100644 --- a/lib/sfio/sftable.c +++ b/lib/sfio/sftable.c @@ -19,7 +19,7 @@ static char *sffmtint(const char *str, int *v) { - for (*v = 0; isdigit(*str); ++str) + for (*v = 0; isdigit((int)*str); ++str) *v = *v * 10 + (*str - '0'); *v -= 1; return (char *) str; @@ -145,7 +145,7 @@ static Fmtpos_t *sffmtpos(Sfio_t * f, const char *form, va_list args, case '.': if ((dot += 1) == 2) base = 0; /* for %s,%c */ - if (isdigit(*form)) { + if (isdigit((int)*form)) { fmt = *form++; goto dot_size; } else if (*form != '*') @@ -194,7 +194,7 @@ static Fmtpos_t *sffmtpos(Sfio_t * f, const char *form, va_list args, case 'I': /* object length */ size = 0; flags = (flags & ~SFFMT_TYPES) | SFFMT_IFLAG; - if (isdigit(*form)) { + if (isdigit((int)*form)) { for (n = *form; isdigit(n); n = *++form) size = size * 10 + (n - '0'); } else if (*form == '*') { diff --git a/lib/sfio/sfvprintf.c b/lib/sfio/sfvprintf.c index d997e52e1..b36dfdebc 100644 --- a/lib/sfio/sfvprintf.c +++ b/lib/sfio/sfvprintf.c @@ -226,7 +226,7 @@ int sfvprintf(Sfio_t * f, const char *form, va_list args) base = 0; /* for %s,%c */ if (*form == 'c' || *form == 's') goto loop_flags; - if (*form && !isalnum(*form) && + if (*form && !isalnum((int)*form) && (form[1] == 'c' || form[1] == 's')) { if (*form == '*') goto do_star; @@ -237,7 +237,7 @@ int sfvprintf(Sfio_t * f, const char *form, va_list args) } } - if (isdigit(*form)) { + if (isdigit((int)*form)) { fmt = *form++; goto dot_size; } else if (*form != '*') @@ -279,7 +279,7 @@ int sfvprintf(Sfio_t * f, const char *form, va_list args) case '8': case '9': dot_size: - for (v = fmt - '0'; isdigit(*form); ++form) + for (v = fmt - '0'; isdigit((int)*form); ++form) v = v * 10 + (*form - '0'); if (*form == '$') { form += 1; @@ -303,7 +303,7 @@ int sfvprintf(Sfio_t * f, const char *form, va_list args) case 'I': /* object length */ size = 0; flags = (flags & ~SFFMT_TYPES) | SFFMT_IFLAG; - if (isdigit(*form)) { + if (isdigit((int)*form)) { for (n = *form; isdigit(n); n = *++form) size = size * 10 + (n - '0'); } else if (*form == '*') { @@ -815,7 +815,7 @@ int sfvprintf(Sfio_t * f, const char *form, va_list args) } e_format: /* build the x.yyyy string */ - if (isalpha(*ep)) + if (isalpha((int)*ep)) goto infinite; sp = endsp = buf + 1; /* reserve space for sign */ *endsp++ = *ep ? *ep++ : '0'; @@ -851,7 +851,7 @@ int sfvprintf(Sfio_t * f, const char *form, va_list args) goto end_efg; f_format: /* data before the decimal point */ - if (isalpha(*ep)) { + if (isalpha((int)*ep)) { infinite: endsp = (sp = ep) + sfslen(); ep = endep; diff --git a/lib/sfio/sfvscanf.c b/lib/sfio/sfvscanf.c index 39ac193c2..078cf462b 100644 --- a/lib/sfio/sfvscanf.c +++ b/lib/sfio/sfvscanf.c @@ -241,7 +241,7 @@ int sfvscanf(Sfio_t * f, const char *form, va_list args) case '.': /* width & base */ dot += 1; - if (isdigit(*form)) { + if (isdigit((int)*form)) { fmt = *form++; goto dot_size; } else if (*form == '*') { @@ -284,7 +284,7 @@ int sfvscanf(Sfio_t * f, const char *form, va_list args) case '8': case '9': dot_size: - for (v = fmt - '0'; isdigit(*form); ++form) + for (v = fmt - '0'; isdigit((int)*form); ++form) v = v * 10 + (*form - '0'); if (*form == '$') { @@ -305,7 +305,7 @@ int sfvscanf(Sfio_t * f, const char *form, va_list args) case 'I': /* object size */ size = 0; flags = (flags & ~SFFMT_TYPES) | SFFMT_IFLAG; - if (isdigit(*form)) { + if (isdigit((int)*form)) { for (n = *form; isdigit(n); n = *++form) size = size * 10 + (n - '0'); } else if (*form == '*') { diff --git a/lib/xdot/xdot.c b/lib/xdot/xdot.c index 5bb1a5919..b03f60c1f 100644 --- a/lib/xdot/xdot.c +++ b/lib/xdot/xdot.c @@ -245,7 +245,7 @@ static char *parseOp(xdot_op * op, char *s, drawfunc_t ops[], int* error) xdot_color clr; *error = 0; - while (isspace(*s)) + while (isspace((int)*s)) s++; switch (*s++) { case 'E': -- 2.40.0