Skip to content

Commit 6b6a259

Browse files
Chris Friedtkartben
authored andcommitted
libc: minimal: ctype: remove unnecessary casts
A review comment in the PR below requested that unnecessary casts were removed from ctype.h in the PR below. #99451 Tested with manual compilation in C and C++ mode with the arguments ```shell gcc -Wconversion -Werror -Wall -Wextra -Wint-conversion clang -Wconversion -Werror -Wall -Wextra -Wint-conversion gcc -Wconversion -Werror -Wall -Wimplicit--Wextra clang++ -Wconversion -Werror -Wall -Wextra ``` and also with `-- -DCONFIG_COMPILER_WARNINGS_AS_ERRORS=y` Signed-off-by: Chris Friedt <[email protected]>
1 parent 6b393c7 commit 6b6a259

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

lib/libc/minimal/include/ctype.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,35 @@ extern "C" {
1515

1616
static inline int isupper(int a)
1717
{
18-
return (int)(((int)'A' <= a) && (a <= (int)'Z'));
18+
return (('A' <= a) && (a <= 'Z'));
1919
}
2020

2121
static inline int isalpha(int c)
2222
{
2323
/* force to lowercase */
24-
c += 32U;
24+
c |= 32;
2525

26-
return (int)(((int)'a' <= c) && (c <= (int)'z'));
26+
return (('a' <= c) && (c <= 'z'));
2727
}
2828

2929
static inline int isspace(int c)
3030
{
31-
return (int)((c == (int)' ') || (((int)'\t' <= c) && (c <= (int)'\r')));
31+
return ((c == ' ') || (('\t' <= c) && (c <= '\r')));
3232
}
3333

3434
static inline int isgraph(int c)
3535
{
36-
return (int)(((int)' ' < c) && (c <= (int)'~'));
36+
return ((' ' < c) && (c <= '~'));
3737
}
3838

3939
static inline int isprint(int c)
4040
{
41-
return (int)(((int)' ' <= c) && (c <= (int)'~'));
41+
return ((' ' <= c) && (c <= '~'));
4242
}
4343

4444
static inline int isdigit(int a)
4545
{
46-
return (int)(((int)'0' <= a) && (a <= (int)'9'));
46+
return (('0' <= a) && (a <= '9'));
4747
}
4848

4949
static inline int isxdigit(int a)
@@ -53,30 +53,29 @@ static inline int isxdigit(int a)
5353
}
5454

5555
/* force to lowercase */
56-
a += 32U;
56+
a |= 32;
5757

58-
return (int)(((int)'a' <= a) && (a <= (int)'f'));
58+
return (('a' <= a) && (a <= 'f'));
5959
}
6060

6161
static inline int tolower(int chr)
6262
{
63-
return (chr >= (int)'A' && chr <= (int)'Z') ? (chr + 32) : (chr);
63+
return (chr >= 'A' && chr <= 'Z') ? (chr + 32) : (chr);
6464
}
6565

6666
static inline int toupper(int chr)
6767
{
68-
return (int)((chr >= (int)'a' && chr <=
69-
(int)'z') ? (chr - 32) : (chr));
68+
return ((chr >= 'a' && chr <= 'z') ? (chr - 32) : (chr));
7069
}
7170

7271
static inline int isalnum(int chr)
7372
{
74-
return (int)(isalpha(chr) || isdigit(chr));
73+
return (isalpha(chr) || isdigit(chr));
7574
}
7675

7776
static inline int iscntrl(int c)
7877
{
79-
return (int)((((unsigned int)c) <= 31U) || (((unsigned int)c) == 127U));
78+
return ((((unsigned int)c) <= 31U) || (((unsigned int)c) == 127U));
8079
}
8180

8281
#ifdef __cplusplus

0 commit comments

Comments
 (0)