Skip to content

Commit

Permalink
Merge pull request #3734 from b4n/ctype-calls
Browse files Browse the repository at this point in the history
Fix many calls to ctype functions
  • Loading branch information
b4n committed May 26, 2023
2 parents 979433d + a76c937 commit 23bacc1
Show file tree
Hide file tree
Showing 52 changed files with 359 additions and 329 deletions.
2 changes: 1 addition & 1 deletion Units/simple-diff.d/input.diff
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ index 0000000..a1bf5f3
+ if (strncmp ((const char*) cp, DiffDelims[delim], 4u) == 0)
+ {
+ cp += 4;
+ if (isspace ((int) *cp)) continue;
+ if (isspace (*cp)) continue;
+ /* when original filename is /dev/null use the new one instead */
+ if (delim == DIFF_DELIM_MINUS &&
+ strncmp ((const char*) cp, "/dev/null", 9u) == 0 &&
Expand Down
2 changes: 1 addition & 1 deletion dsl/dsl.c
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ static EsObject* caseop (EsObject *o, int (*op)(int))
char *r = strdup (s);

for (char *tmp = r; *tmp != '\0'; tmp++)
*tmp = op (*tmp);
*tmp = op ((unsigned char) *tmp);

EsObject *q = es_object_autounref (es_string_new (r));
free (r);
Expand Down
2 changes: 1 addition & 1 deletion dsl/optscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ name_or_number_new (const char* s, void *data)
const char *t = s;
while (*t)
{
if (!isdigit ((int)*t))
if (!isdigit ((unsigned char) *t))
{
number = false;
break;
Expand Down
6 changes: 3 additions & 3 deletions main/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static char *nextStringArg (const char** const next)
const char* start;

Assert (*next != NULL);
for (start = *next ; isspace ((int) *start) ; ++start)
for (start = *next ; isspace ((unsigned char) *start) ; ++start)
;
if (*start == '\0')
*next = start;
Expand All @@ -40,7 +40,7 @@ static char *nextStringArg (const char** const next)
size_t length;
const char* end;

for (end = start ; *end != '\0' && ! isspace ((int) *end) ; ++end)
for (end = start; *end != '\0' && ! isspace ((unsigned char) *end); ++end)
;
length = end - start;
Assert (length > 0);
Expand Down Expand Up @@ -156,7 +156,7 @@ static char* nextFileLine (FILE* const fp)

static bool isCommentLine (char* line)
{
while (isspace(*line))
while (isspace((unsigned char) *line))
++line;
return (*line == '#');
}
Expand Down
4 changes: 2 additions & 2 deletions main/field.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ static const char* renderCompactInputLine (vString *b, const char *const line)

/* Consume repeating white space.
*/
while (next = *(p+1) , isspace (next) && next != NEWLINE)
while (next = (unsigned char) *(p+1), isspace (next) && next != NEWLINE)
++p;
c = ' '; /* force space character for any white space */
}
Expand Down Expand Up @@ -1328,7 +1328,7 @@ extern int defineField (fieldDefinition *def, langType language)
Assert (def->name);
for (i = 0; i < strlen (def->name); i++)
{
Assert ( isalpha (def->name [i]) );
Assert ( isalpha ((unsigned char) def->name [i]) );
}
def->letter = NUL_FIELD_LETTER;

Expand Down
8 changes: 4 additions & 4 deletions main/keyword.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ static hashEntry *getHashTableEntry (unsigned long hashedValue)
static unsigned int hashValue (const char *const string, langType language,
unsigned int maxLen, bool *maxLenReached)
{
const signed char *p;
const char *p;
unsigned int h = 5381;

Assert (string != NULL);

/* "djb" hash as used in g_str_hash() in glib */
for (p = (const signed char *)string; *p != '\0'; p++)
for (p = string; *p != '\0'; p++)
{
h = (h << 5) + h + tolower (*p);
h = (h << 5) + h + (signed char) tolower ((unsigned char) *p);

if (p > (const signed char *)string + maxLen)
if (p > string + maxLen)
{
*maxLenReached = true;
return 0;
Expand Down
2 changes: 1 addition & 1 deletion main/kind.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static void initRoleObject (roleObject *robj, roleDefinition *rdef, freeRoleDefF
#ifdef DEBUG
size_t len = strlen (rdef->name);
for (int i = 0; i < len; i++)
Assert (isalnum (rdef->name [i]));
Assert (isalnum ((unsigned char) rdef->name [i]));
#endif
robj->def = rdef;
robj->free = freefunc;
Expand Down
14 changes: 7 additions & 7 deletions main/lregex.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ static void pre_ptrn_flag_guest_long (const char* const s, const char* const v,
{
const char *n_tmp = v + 1;
const char *n = n_tmp;
for (; isdigit (*n_tmp); n_tmp++);
for (; isdigit ((unsigned char) *n_tmp); n_tmp++);
char c = *n_tmp;
*(char *)n_tmp = '\0';
if (!strToInt (n, 10, &(guest->lang.spec.patternGroup)))
Expand Down Expand Up @@ -886,7 +886,7 @@ static void pre_ptrn_flag_guest_long (const char* const s, const char* const v,
{
char *n = tmp;

for (; isdigit (*tmp); tmp++);
for (; isdigit ((unsigned char) *tmp); tmp++);
char c = *tmp;
*tmp = '\0';
if (!strToInt (n, 10, &(current->patternGroup)))
Expand Down Expand Up @@ -1599,7 +1599,7 @@ static vString* substitute (
const char* p;
for (p = out ; *p != '\0' ; p++)
{
if (*p == '\\' && isdigit ((int) *++p))
if (*p == '\\' && isdigit ((unsigned char) *++p))
{
const int dig = *p - '0';
if (0 < dig && dig < nmatch && pmatch [dig].rm_so != -1)
Expand Down Expand Up @@ -2294,7 +2294,7 @@ static regexPattern *addTagRegexInternal (struct lregexControlBlock *lcb,
{
if (p == kindName)
{
if (!isalpha(*p))
if (!isalpha((unsigned char) *p))
error (FATAL,
"A kind name doesn't start with an alphabetical character: "
"'%s' in \"--%s-%s\" option",
Expand All @@ -2310,7 +2310,7 @@ static regexPattern *addTagRegexInternal (struct lregexControlBlock *lcb,
* in which Exuberant-ctags users define kind names with whitespaces.
* "FATAL" error breaks the compatibility.
*/
if (!isalnum(*p))
if (!isalnum((unsigned char) *p))
error (/* regptype == REG_PARSER_SINGLE_LINE? WARNING: */ FATAL,
"Non-alphanumeric char is used in kind name: "
"'%s' in \"--%s-%s\" option",
Expand Down Expand Up @@ -2433,7 +2433,7 @@ static void addTagRegexOption (struct lregexControlBlock *lcb,
const char *c;
for (c = pattern; *c; c++)
{
if (! (isalnum(*c) || *c == '_'))
if (! (isalnum((unsigned char) *c) || *c == '_'))
{
if (*c && (*(c + 1) != '^'))
{
Expand Down Expand Up @@ -2652,7 +2652,7 @@ extern void addRegexTable (struct lregexControlBlock *lcb, const char *name)
{
const char *c;
for (c = name; *c; c++)
if (! (isalnum(*c) || *c == '_'))
if (! (isalnum((unsigned char) *c) || *c == '_'))
error (FATAL, "`%c' in \"%s\" is not acceptable as part of table name", *c, name);

if (getTableIndexForName(lcb, name) >= 0)
Expand Down
2 changes: 1 addition & 1 deletion main/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -2604,7 +2604,7 @@ static void processIgnoreOption (const char *const list, int IgnoreOrDefine)
addIgnoreListFromFile (lang, fileName);
}
#if defined (WIN32)
else if (isalpha (list [0]) && list [1] == ':')
else if (isalpha ((unsigned char) list [0]) && list [1] == ':')
addIgnoreListFromFile (lang, list);
#endif
else if (strcmp (list, "-") == 0)
Expand Down
48 changes: 25 additions & 23 deletions main/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ static bool processLangDefineScopesep(const langType language,
error (FATAL,
"the kind letter `%c' in \"--%s\" option is reserved for \"%s\" kind and no separator can be assigned to",
KIND_FILE_DEFAULT_LETTER, option, KIND_FILE_DEFAULT_NAME);
else if (isalpha (parentKletter))
else if (isalpha ((unsigned char) parentKletter))
{
kindDefinition *kdef = getKindForLetter (parser->kindControlBlock, parentKletter);
if (kdef == NULL)
Expand Down Expand Up @@ -623,7 +623,7 @@ static bool processLangDefineScopesep(const langType language,
error (FATAL,
"the kind letter `%c' in \"--%s\" option is reserved for \"%s\" kind and no separator can be assigned to",
KIND_FILE_DEFAULT_LETTER, option, KIND_FILE_DEFAULT_NAME);
else if (isalpha (kletter))
else if (isalpha ((unsigned char) kletter))
{
kindDefinition *kdef = getKindForLetter (parser->kindControlBlock, kletter);
if (kdef == NULL)
Expand Down Expand Up @@ -748,9 +748,9 @@ static vString* determineInterpreter (const char* const cmd)
do
{
vStringClear (interpreter);
for ( ; isspace ((int) *p) ; ++p)
for ( ; isspace ((unsigned char) *p) ; ++p)
; /* no-op */
for ( ; *p != '\0' && ! isspace ((int) *p) ; ++p)
for ( ; *p != '\0' && ! isspace ((unsigned char) *p) ; ++p)
vStringPut (interpreter, *p);
} while (strcmp (vStringValue (interpreter), "env") == 0);
return interpreter;
Expand Down Expand Up @@ -795,7 +795,7 @@ static bool isShellZsh (const char *p)

if (*p == ':')
p++;
while (isspace ((int) *p))
while (isspace ((unsigned char) *p))
p++;

if (strncmp (p, "\"zsh\"", 5) == 0
Expand All @@ -813,16 +813,16 @@ static vString* determineEmacsModeAtFirstLine (const char* const line)
goto out;
p += strlen("-*-");

for ( ; isspace ((int) *p) ; ++p)
for ( ; isspace ((unsigned char) *p) ; ++p)
; /* no-op */

if (strncasecmp(p, "mode:", strlen("mode:")) == 0)
{
/* -*- mode: MODE; -*- */
p += strlen("mode:");
for ( ; isspace ((int) *p) ; ++p)
for ( ; isspace ((unsigned char) *p) ; ++p)
; /* no-op */
for ( ; *p != '\0' && isLanguageNameChar ((int) *p) ; ++p)
for ( ; *p != '\0' && isLanguageNameChar ((unsigned char) *p) ; ++p)
vStringPut (mode, *p);

if ((strcmp(vStringValue (mode), "sh") == 0
Expand All @@ -838,10 +838,10 @@ static vString* determineEmacsModeAtFirstLine (const char* const line)
if (end == NULL)
goto out;

for ( ; p < end && isLanguageNameChar ((int) *p) ; ++p)
for ( ; p < end && isLanguageNameChar ((unsigned char) *p) ; ++p)
vStringPut (mode, *p);

for ( ; isspace ((int) *p) ; ++p)
for ( ; isspace ((unsigned char) *p) ; ++p)
; /* no-op */
if (strncmp(p, "-*-", strlen("-*-")) != 0)
vStringClear (mode);
Expand Down Expand Up @@ -888,9 +888,9 @@ static vString* determineEmacsModeAtEOF (MIO* const fp)
headerFound = false;

p += strlen ("mode:");
for ( ; isspace ((int) *p) ; ++p)
for ( ; isspace ((unsigned char) *p) ; ++p)
; /* no-op */
for ( ; *p != '\0' && isLanguageNameChar ((int) *p) ; ++p)
for ( ; *p != '\0' && isLanguageNameChar ((unsigned char) *p) ; ++p)
vStringPut (mode, *p);

is_shell_mode = ((strcasecmp (vStringValue (mode), "sh") == 0
Expand All @@ -903,7 +903,7 @@ static vString* determineEmacsModeAtEOF (MIO* const fp)
else if (is_shell_mode && (p = strstr (line, "sh-set-shell")))
{
p += strlen("sh-set-shell");
while (isspace ((int) *p))
while (isspace ((unsigned char) *p))
p++;
if (strncmp (p, "\"zsh\"", 5) == 0)
vStringCopyS (mode, "Zsh");
Expand Down Expand Up @@ -954,7 +954,7 @@ static vString* determineVimFileType (const char *const modeline)
continue;

p += strlen(filetype_prefix[i]);
for ( ; *p != '\0' && isalnum ((int) *p) ; ++p)
for ( ; *p != '\0' && isalnum ((unsigned char) *p) ; ++p)
vStringPut (filetype, *p);
break;
}
Expand Down Expand Up @@ -1011,7 +1011,7 @@ static vString* extractVimFileTypeCommon(MIO* input, bool eof)
if ((p = strstr (vStringValue (ring[j]), prefix[k])) != NULL)
{
p += strlen(prefix[k]);
for ( ; isspace ((int) *p) ; ++p)
for ( ; isspace ((unsigned char) *p) ; ++p)
; /* no-op */
filetype = determineVimFileType(p);
break;
Expand Down Expand Up @@ -1066,9 +1066,11 @@ static vString* determineZshAutoloadTag (const char *const modeline,
#compdef ...
#autoload [ OPTIONS ] */

if (((strncmp (modeline, "#compdef", 8) == 0) && isspace (*(modeline + 8)))
if (((strncmp (modeline, "#compdef", 8) == 0)
&& isspace ((unsigned char) *(modeline + 8)))
|| ((strncmp (modeline, "#autoload", 9) == 0)
&& (isspace (*(modeline + 9)) || *(modeline + 9) == '\0')))
&& (isspace ((unsigned char) *(modeline + 9))
|| *(modeline + 9) == '\0')))
return vStringNewInit ("zsh");
else
return NULL;
Expand Down Expand Up @@ -2701,7 +2703,7 @@ static bool processLangDefineKind(const langType language,
{
if (p == name_start)
{
if (!isalpha(*p))
if (!isalpha((unsigned char) *p))
{
char *name_in_msg = eStrndup (name_start, marker_end - name_start);
error (FATAL,
Expand All @@ -2712,7 +2714,7 @@ static bool processLangDefineKind(const langType language,
}
else
{
if (!isalnum (*p))
if (!isalnum ((unsigned char) *p))
{
char *name_in_msg = eStrndup (name_start, marker_end - name_start);
error (FATAL,
Expand Down Expand Up @@ -2833,7 +2835,7 @@ static bool processLangDefineRole(const langType language,
const char * tmp_start = p;
while (p != tmp_end)
{
if (!isalnum (*p))
if (!isalnum ((unsigned char) *p))
error (FATAL, "unacceptable char as part of role name in \"--%s\" option: %c",
option, *p);
p++;
Expand Down Expand Up @@ -3518,7 +3520,7 @@ static bool processLangDefineParam (const langType language,

for (; p < name_end; p++)
{
if (!isalnum (*p) && *p != '_')
if (!isalnum ((unsigned char) *p) && *p != '_')
error (FATAL, "unacceptable char as part of extra name in \"--%s\" option",
option);
}
Expand Down Expand Up @@ -3914,7 +3916,7 @@ static bool processLangDefineExtra (const langType language,

for (; p < name_end; p++)
{
if (!isalnum (*p))
if (!isalnum ((unsigned char) *p))
error (FATAL, "unacceptable char as part of extra name in \"--%s\" option",
option);
}
Expand Down Expand Up @@ -3983,7 +3985,7 @@ static bool processLangDefineField (const langType language,

for (; p < name_end; p++)
{
if (!isalpha (*p))
if (!isalpha ((unsigned char) *p))
error (FATAL, "unacceptable char as part of field name in \"--%s\" option",
option);
}
Expand Down
4 changes: 2 additions & 2 deletions main/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ static unsigned long readLineNumber (char **str)

skipWhite (str);
s = *str;
while (*s != '\0' && isdigit (*s))
while (*s != '\0' && isdigit ((unsigned char) *s))
{
lNum = (lNum * 10) + (*s - '0');
s++;
Expand Down Expand Up @@ -578,7 +578,7 @@ static bool parseLineDirective (char *s)
skipWhite (&s);
DebugStatement ( const char* lineStr = ""; )

if (isdigit (*s))
if (isdigit ((unsigned char) *s))
result = true;
else if (strncmp (s, "line", 4) == 0)
{
Expand Down
Loading

0 comments on commit 23bacc1

Please sign in to comment.