Skip to content

Commit 0889cfa

Browse files
authored
Merge pull request #8283 from tautschnig/features/tolower
C library: add __to{lower,upper} as alternative names for {tolower,toupper}
2 parents f18b509 + 98d09fb commit 0889cfa

File tree

6 files changed

+53
-8
lines changed

6 files changed

+53
-8
lines changed

regression/cbmc-library/tolower-01/main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
int main()
55
{
6-
tolower();
7-
assert(0);
6+
int x;
7+
int r = tolower(x);
8+
assert(r >= x);
89
return 0;
910
}

regression/cbmc-library/tolower-01/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/toupper-01/main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
int main()
55
{
6-
toupper();
7-
assert(0);
6+
int x;
7+
int r = toupper(x);
8+
assert(r <= x);
89
return 0;
910
}

regression/cbmc-library/toupper-01/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

src/ansi-c/library/ctype.c

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,52 @@ int isupper(int c)
9595
int isxdigit(int c)
9696
{ return (c>='A' && c<='F') || (c>='a' && c<='f') || (c>='0' && c<='9'); }
9797

98+
/* FUNCTION: __CPROVER_tolower */
99+
100+
int __CPROVER_tolower(int c)
101+
{
102+
return (c >= 'A' && c <= 'Z') ? c + ('a' - 'A') : c;
103+
}
104+
98105
/* FUNCTION: tolower */
99106

107+
int __CPROVER_tolower(int c);
108+
100109
int tolower(int c)
101-
{ return (c>='A' && c<='Z')?c+('a'-'A'):c; }
110+
{
111+
return __CPROVER_tolower(c);
112+
}
113+
114+
/* FUNCTION: __tolower */
115+
116+
int __CPROVER_tolower(int c);
117+
118+
int __tolower(int c)
119+
{
120+
return __CPROVER_tolower(c);
121+
}
122+
123+
/* FUNCTION: __CPROVER_toupper */
124+
125+
int __CPROVER_toupper(int c)
126+
{
127+
return (c >= 'a' && c <= 'z') ? c - ('a' - 'A') : c;
128+
}
102129

103130
/* FUNCTION: toupper */
104131

132+
int __CPROVER_toupper(int c);
133+
105134
int toupper(int c)
106-
{ return (c>='a' && c<='z')?c-('a'-'A'):c; }
135+
{
136+
return __CPROVER_toupper(c);
137+
}
138+
139+
/* FUNCTION: __toupper */
140+
141+
int __CPROVER_toupper(int c);
142+
143+
int __toupper(int c)
144+
{
145+
return __CPROVER_toupper(c);
146+
}

src/ansi-c/library_check.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@ perl -p -i -e 's/^__stdio_common_vsprintf\n//' __functions # snprintf, Windows
5454
perl -p -i -e 's/^__stdio_common_vsscanf\n//' __functions # sscanf, Windows
5555
perl -p -i -e 's/^__srget\n//' __functions # gets, FreeBSD
5656
perl -p -i -e 's/^__swbuf\n//' __functions # putc, FreeBSD
57+
perl -p -i -e 's/^__tolower\n//' __functions # tolower, macOS
58+
perl -p -i -e 's/^__toupper\n//' __functions # toupper, macOS
5759

5860
# Some functions are covered by existing tests:
5961
perl -p -i -e 's/^__CPROVER_(creat|fcntl|open|openat)\n//' __functions # creat, fcntl, open, openat
62+
perl -p -i -e 's/^__CPROVER_(tolower|toupper)\n//' __functions # tolower, toupper
6063
perl -p -i -e 's/^(creat|fcntl|open|openat)64\n//' __functions # same as creat, fcntl, open, openat
6164
perl -p -i -e 's/^__CPROVER_deallocate\n//' __functions # free-01
6265
perl -p -i -e 's/^__builtin_alloca\n//' __functions # alloca-01

0 commit comments

Comments
 (0)