Skip to content

Commit

Permalink
all: Fix usage of ctype functions
Browse files Browse the repository at this point in the history
ctype functions take int as an argument and expect either unsigned char
(values 0-255) or EOF (-1). So explicitly cast signed and not-specified
char type variables to unsigned char.
  • Loading branch information
pali committed Aug 14, 2021
1 parent b08c75d commit 6b4cafc
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion libudffs/misc.c
Expand Up @@ -98,7 +98,7 @@ uint32_t strtou32(const char *str, int base, int *failed)
errno = 0;
ret = strtoll(str, &endptr, base);
/* strto* skips leading whitespaces, so detect them via isspace */
*failed = (!*str || isspace(*str) || *endptr || errno || ret < 0 || ret > UINT32_MAX) ? 1 : 0;
*failed = (!*str || isspace((unsigned char)*str) || *endptr || errno || ret < 0 || ret > UINT32_MAX) ? 1 : 0;
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion mkudffs/options.c
Expand Up @@ -385,7 +385,7 @@ void parse_args(int argc, char *argv[], struct udf_disc *disc, char **device, in
}
for (i = 0; i < 16; ++i)
{
if (!isxdigit(optarg[i]) || (!isdigit(optarg[i]) && !islower(optarg[i])))
if (!isxdigit((unsigned char)optarg[i]) || (!isdigit((unsigned char)optarg[i]) && !islower((unsigned char)optarg[i])))
{
fprintf(stderr, "%s: Error: Option --uuid is not in lowercase hexadecimal digit format\n", appname);
exit(1);
Expand Down
2 changes: 1 addition & 1 deletion udflabel/options.c
Expand Up @@ -130,7 +130,7 @@ static void process_uuid_arg(const char *arg, char *new_uuid)

for (i = 0; i < 16; ++i)
{
if (!isxdigit(arg[i]) || (!isdigit(arg[i]) && !islower(arg[i])))
if (!isxdigit((unsigned char)arg[i]) || (!isdigit((unsigned char)arg[i]) && !islower((unsigned char)arg[i])))
{
fprintf(stderr, "%s: Error: Option --uuid is not in lowercase hexadecimal digit format\n", appname);
exit(1);
Expand Down

0 comments on commit 6b4cafc

Please sign in to comment.