Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
frama-c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
frama-c
Commits
659b93f6
Commit
659b93f6
authored
5 years ago
by
Andre Maroneze
Browse files
Options
Downloads
Patches
Plain Diff
[Libc] fix some specs in stdio.h
parent
b337c046
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
share/libc/stdio.h
+90
-20
90 additions, 20 deletions
share/libc/stdio.h
tests/libc/stdio_h.c
+10
-0
10 additions, 0 deletions
tests/libc/stdio_h.c
with
100 additions
and
20 deletions
share/libc/stdio.h
+
90
−
20
View file @
659b93f6
...
...
@@ -222,9 +222,13 @@ extern int fgetc(FILE *stream);
/*@
requires valid_stream: \valid(stream);
assigns s[0..size] \from indirect:size, indirect:*stream;
requires room_s: \valid(s+(0..size-1));
assigns s[0..size-1] \from indirect:size, indirect:*stream;
assigns \result \from s, indirect:size, indirect:*stream;
ensures result_null_or_same: \result == \null || \result == s;
ensures initialization:at_least_one:\result != \null ==> \initialized(&s[0]);
// the return value does not tell how many characters were written,
// so we can only ensure the first one was initialized
ensures terminated_string_on_success:
\result != \null ==> valid_string(s);
*/
...
...
@@ -244,14 +248,26 @@ extern int getc(FILE *stream);
/*@ assigns \result \from *__fc_stdin ; */
extern
int
getchar
(
void
);
// Number of characters that will read by gets()
/*@
assigns s[..] \from *__fc_stdin ;
assigns \result \from s, __fc_stdin;
axiomatic GetsLength {
logic size_t gets_length{L} reads *__fc_stdin;
}
*/
/*@
requires room_s: \valid(s+(0..gets_length));
assigns s[0..gets_length] \from *__fc_stdin ;
assigns \result \from s, *__fc_stdin;
assigns *__fc_stdin \from *__fc_stdin;
ensures result_null_or_same: \result == s || \result == \null;
*/
extern
char
*
gets
(
char
*
s
);
/*@ assigns *stream \from c; */
/*@
requires valid_stream: \valid(stream);
assigns *stream \from c;
*/
extern
int
putc
(
int
c
,
FILE
*
stream
);
/*@ assigns *__fc_stdout \from c; */
...
...
@@ -260,7 +276,10 @@ extern int putchar(int c);
/*@ assigns *__fc_stdout \from s[..]; */
extern
int
puts
(
const
char
*
s
);
/*@ assigns *stream \from c; */
/*@
requires valid_stream: \valid(stream);
assigns *stream \from c;
*/
extern
int
ungetc
(
int
c
,
FILE
*
stream
);
/*@
...
...
@@ -311,50 +330,101 @@ extern int fsetpos(FILE *stream, const fpos_t *pos);
*/
extern
long
int
ftell
(
FILE
*
stream
);
/*@ assigns *stream \from \nothing; */
/*@
requires valid_stream: \valid(stream);
assigns *stream \from \nothing;
*/
extern
void
rewind
(
FILE
*
stream
);
/*@ assigns *stream \from \nothing; */
/*@
requires valid_stream: \valid(stream);
assigns *stream \from \nothing;
*/
extern
void
clearerr
(
FILE
*
stream
);
/*@ assigns \result \from *stream ;*/
/*@
requires valid_stream: \valid(stream);
assigns \result \from *stream;
*/
extern
int
feof
(
FILE
*
stream
);
/*@ assigns \result \from *stream ;*/
/*@
requires valid_stream: \valid(stream);
assigns \result \from *stream;
*/
extern
int
fileno
(
FILE
*
stream
);
/*@ assigns *stream \from \nothing ;*/
/*@
requires valid_stream: \valid(stream);
assigns *stream \from \nothing;
*/
extern
void
flockfile
(
FILE
*
stream
);
/*@ assigns *stream \from \nothing ;*/
/*@
requires valid_stream: \valid(stream);
assigns *stream \from \nothing;
*/
extern
void
funlockfile
(
FILE
*
stream
);
/*@ assigns \result,*stream \from \nothing ;*/
/*@
requires valid_stream: \valid(stream);
assigns \result,*stream \from \nothing;
*/
extern
int
ftrylockfile
(
FILE
*
stream
);
/*@ assigns \result \from *stream ;*/
/*@
requires valid_stream: \valid(stream);
assigns \result \from *stream;
*/
extern
int
ferror
(
FILE
*
stream
);
/*@ assigns __fc_stdout \from __fc_errno, s[..]; */
/*@
requires valid_string_s: valid_read_string(s);
assigns __fc_stdout \from __fc_errno, s[..];
*/
extern
void
perror
(
const
char
*
s
);
/*@ assigns \result,*stream \from *stream; */
/*@
requires valid_stream: \valid(stream);
assigns \result,*stream \from *stream;
*/
extern
int
getc_unlocked
(
FILE
*
stream
);
/*@ assigns \result \from *__fc_stdin ; */
extern
int
getchar_unlocked
(
void
);
/*@ assigns *stream \from c; */
/*@
requires valid_stream: \valid(stream);
assigns *stream \from c;
*/
extern
int
putc_unlocked
(
int
c
,
FILE
*
stream
);
/*@ assigns *__fc_stdout \from c; */
extern
int
putchar_unlocked
(
int
c
);
/*@ assigns *stream \from \nothing; */
/*@
requires valid_stream: \valid(stream);
assigns *stream \from \nothing;
*/
extern
void
clearerr_unlocked
(
FILE
*
stream
);
/*@ assigns \result \from *stream ;*/
/*@
requires valid_stream: \valid(stream);
assigns \result \from *stream;
*/
extern
int
feof_unlocked
(
FILE
*
stream
);
/*@ assigns \result \from *stream ;*/
/*@
requires valid_stream: \valid(stream);
assigns \result \from *stream;
*/
extern
int
ferror_unlocked
(
FILE
*
stream
);
/*@ assigns \result \from *stream ;*/
/*@
requires valid_stream: \valid(stream);
assigns \result \from *stream;
*/
extern
int
fileno_unlocked
(
FILE
*
stream
);
extern
int
fflush_unlocked
(
FILE
*
stream
);
extern
int
fgetc_unlocked
(
FILE
*
stream
);
extern
int
fputc_unlocked
(
int
c
,
FILE
*
stream
);
...
...
This diff is collapsed.
Click to expand it.
tests/libc/stdio_h.c
+
10
−
0
View file @
659b93f6
...
...
@@ -29,5 +29,15 @@ int main() {
if
(
!
redirected
)
return
3
;
printf
(
"redirected to file"
);
fclose
(
redirected
);
char
fgets_buf0
[
1
];
char
*
fgets_res
=
fgets
(
fgets_buf0
,
1
,
f
);
// ok
if
(
!
fgets_res
)
return
1
;
//@ check \initialized(&fgets_buf0[0]);
if
(
nondet
)
{
fgets
(
fgets_buf0
,
2
,
f
);
// error: buf too small
//@ assert unreachable: \false;
}
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment