Explicitly cast chars to unsigned chars for <ctype.h> functions

Apply the semantic patch to catch all the places where we pass 'char' to
the <ctype.h> family of functions (isalpha() and friends, toupper(),
tolower()).

(cherry picked from commit 29caa6d1f0)
This commit is contained in:
Ondřej Surý
2023-09-20 17:23:28 +02:00
parent c2e835989f
commit b354e10793
4 changed files with 9 additions and 5 deletions

View File

@@ -474,7 +474,7 @@ get_parameter_value(const char *input, const char *key) {
for (i = 0; i < 255; i++) {
value[i] = keystart[keylen + i];
if (isspace(value[i]) || value[i] == '\0') {
if (isspace((unsigned char)value[i]) || value[i] == '\0') {
value[i] = '\0';
break;
}

View File

@@ -2057,7 +2057,7 @@ decvalue(char value) {
* isascii() is valid for full range of int values, no need to
* mask or cast.
*/
if (!isascii(value)) {
if (!isascii((unsigned char)value)) {
return (-1);
}
if ((s = strchr(decdigits, value)) == NULL) {

View File

@@ -569,10 +569,14 @@ isc_file_isabsolute(const char *filename) {
if ((filename[0] == '\\') && (filename[1] == '\\')) {
return (true);
}
if (isalpha(filename[0]) && filename[1] == ':' && filename[2] == '\\') {
if (isalpha((unsigned char)filename[0]) && filename[1] == ':' &&
filename[2] == '\\')
{
return (true);
}
if (isalpha(filename[0]) && filename[1] == ':' && filename[2] == '/') {
if (isalpha((unsigned char)filename[0]) && filename[1] == ':' &&
filename[2] == '/')
{
return (true);
}
return (false);

View File

@@ -70,7 +70,7 @@ is_ntfs(const char *file) {
* Look for c:\path\... style, c:/path/... or \\computer\shar\path...
* the UNC style file specs
*/
if (isalpha(filename[0]) && filename[1] == ':' &&
if (isalpha((unsigned char)filename[0]) && filename[1] == ':' &&
(filename[2] == '\\' || filename[2] == '/'))
{
/* Copy 'c:\' or 'c:/' and NUL terminate. */