From: Wayne Davison Date: Thu, 9 Nov 2006 02:14:38 +0000 (+0000) Subject: Use a new isSpace() inline function to call isspace() safely X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/commitdiff_plain/a8facdc09070ba9d01f67de1b08e2704ca34c440 Use a new isSpace() inline function to call isspace() safely when using a signed character pointer. --- diff --git a/popt/poptconfig.c b/popt/poptconfig.c index 63c3ee29..9733d152 100644 --- a/popt/poptconfig.c +++ b/popt/poptconfig.c @@ -30,20 +30,20 @@ static void configLine(poptContext con, char * line) if (strncmp(line, con->appName, nameLength)) return; line += nameLength; - if (*line == '\0' || !isspace(*line)) return; + if (*line == '\0' || !isSpace(line)) return; - while (*line != '\0' && isspace(*line)) line++; + while (*line != '\0' && isSpace(line)) line++; entryType = line; - while (*line == '\0' || !isspace(*line)) line++; + while (*line == '\0' || !isSpace(line)) line++; *line++ = '\0'; - while (*line != '\0' && isspace(*line)) line++; + while (*line != '\0' && isSpace(line)) line++; if (*line == '\0') return; opt = line; - while (*line == '\0' || !isspace(*line)) line++; + while (*line == '\0' || !isSpace(line)) line++; *line++ = '\0'; - while (*line != '\0' && isspace(*line)) line++; + while (*line != '\0' && isSpace(line)) line++; if (*line == '\0') return; /*@-temptrans@*/ /* FIX: line alias is saved */ @@ -134,7 +134,7 @@ int poptReadConfigFile(poptContext con, const char * fn) case '\n': *dst = '\0'; dst = buf; - while (*dst && isspace(*dst)) dst++; + while (*dst && isSpace(dst)) dst++; if (*dst && *dst != '#') configLine(con, dst); chptr++; diff --git a/popt/popthelp.c b/popt/popthelp.c index eb735ffb..70560540 100644 --- a/popt/popthelp.c +++ b/popt/popthelp.c @@ -381,9 +381,9 @@ static void singleOptionHelp(FILE * fp, size_t maxLeftCol, char format[16]; ch = help + lineLength - 1; - while (ch > help && !isspace(*ch)) ch--; + while (ch > help && !isSpace(ch)) ch--; if (ch == help) break; /* give up */ - while (ch > (help + 1) && isspace(*ch)) ch--; + while (ch > (help + 1) && isSpace(ch)) ch--; ch++; snprintf(format, sizeof format, "%%.%ds\n%%%ds", (int) (ch - help), (int) indentLength); @@ -391,7 +391,7 @@ static void singleOptionHelp(FILE * fp, size_t maxLeftCol, fprintf(fp, format, help, " "); /*@=formatconst@*/ help = ch; - while (isspace(*help) && *help) help++; + while (isSpace(help) && *help) help++; helpLength = strlen(help); } /*@=boundsread@*/ diff --git a/popt/poptint.h b/popt/poptint.h index 5e75712c..bec7c976 100644 --- a/popt/poptint.h +++ b/popt/poptint.h @@ -22,6 +22,12 @@ _free(/*@only@*/ /*@null@*/ const void * p) return NULL; } +static inline int +isSpace(const char *ptr) +{ + return isspace(*(unsigned char *)ptr); +} + /* Bit mask macros. */ /*@-exporttype -redef @*/ typedef unsigned int __pbm_bits; diff --git a/popt/poptparse.c b/popt/poptparse.c index ccc2ac82..7bc3a963 100644 --- a/popt/poptparse.c +++ b/popt/poptparse.c @@ -8,6 +8,8 @@ #include "system.h" +#include "poptint.h" + #define POPT_ARGV_ARRAY_GROW_DELTA 5 /*@-boundswrite@*/ @@ -81,7 +83,7 @@ int poptParseArgvString(const char * s, int * argcPtr, const char *** argvPtr) if (*src != quote) *buf++ = '\\'; } *buf++ = *src; - } else if (isspace(*src)) { + } else if (isSpace(src)) { if (*argv[argc] != '\0') { buf++, argc++; if (argc == argvAlloced) { @@ -157,7 +159,7 @@ int poptConfigFileToString(FILE *fp, char ** argstrp, /*@unused@*/ UNUSED(int fl p = line; /* loop until first non-space char or EOL */ - while( *p != '\0' && isspace(*p) ) + while( *p != '\0' && isSpace(p) ) p++; linelen = strlen(p); @@ -169,13 +171,13 @@ int poptConfigFileToString(FILE *fp, char ** argstrp, /*@unused@*/ UNUSED(int fl q = p; - while (*q != '\0' && (!isspace(*q)) && *q != '=') + while (*q != '\0' && (!isSpace(q)) && *q != '=') q++; - if (isspace(*q)) { + if (isSpace(q)) { /* a space after the name, find next non space */ *q++='\0'; - while( *q != '\0' && isspace((int)*q) ) q++; + while( *q != '\0' && isSpace(q) ) q++; } if (*q == '\0') { /* single command line option (ie, no name=val, just name) */ @@ -197,14 +199,14 @@ int poptConfigFileToString(FILE *fp, char ** argstrp, /*@unused@*/ UNUSED(int fl *q++ = '\0'; /* find next non-space letter of value */ - while (*q != '\0' && isspace(*q)) + while (*q != '\0' && isSpace(q)) q++; if (*q == '\0') continue; /* XXX silently ignore missing value */ /* now, loop and strip all ending whitespace */ x = p + linelen; - while (isspace(*--x)) + while (isSpace(--x)) *x = 0; /* null out last char if space (including fgets() NL) */ /* rest of line accept */