Skip to content

Commit 801fa73

Browse files
authored
Merge pull request #7903 from tautschnig/features/strftime
C library: model strftime
2 parents 7e452e5 + 6101550 commit 801fa73

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <assert.h>
2+
#include <time.h>
3+
4+
#ifndef __DARWIN_ALIAS
5+
size_t _strftime(char *s, size_t max, const char *format, const struct tm *tm);
6+
#endif
7+
8+
int main()
9+
{
10+
char dest[3];
11+
struct tm input;
12+
size_t result = _strftime(dest, 3, "%y", &input);
13+
assert(result < 3);
14+
return 0;
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--pointer-check --bounds-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <assert.h>
2+
#include <time.h>
3+
4+
int main()
5+
{
6+
char dest[3];
7+
struct tm input;
8+
size_t result = strftime(dest, 3, "%y", &input);
9+
assert(result < 3);
10+
return 0;
11+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--pointer-check --bounds-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

src/ansi-c/library/time.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,50 @@ char *ctime(const time_t *clock)
218218
return ctime_result;
219219
#endif
220220
}
221+
222+
/* FUNCTION: strftime */
223+
224+
#ifndef __CPROVER_TIME_H_INCLUDED
225+
# include <time.h>
226+
# define __CPROVER_TIME_H_INCLUDED
227+
#endif
228+
229+
__CPROVER_size_t __VERIFIER_nondet_size_t(void);
230+
231+
__CPROVER_size_t
232+
strftime(char *s, __CPROVER_size_t max, const char *format, const struct tm *tm)
233+
{
234+
(void)*format;
235+
(void)*tm;
236+
__CPROVER_havoc_slice(s, max);
237+
__CPROVER_size_t length = __VERIFIER_nondet_size_t();
238+
if(length >= max)
239+
return 0;
240+
s[length] = '\0';
241+
return length;
242+
}
243+
244+
/* FUNCTION: _strftime */
245+
246+
#ifndef __CPROVER_TIME_H_INCLUDED
247+
# include <time.h>
248+
# define __CPROVER_TIME_H_INCLUDED
249+
#endif
250+
251+
__CPROVER_size_t __VERIFIER_nondet_size_t(void);
252+
253+
__CPROVER_size_t _strftime(
254+
char *s,
255+
__CPROVER_size_t max,
256+
const char *format,
257+
const struct tm *tm)
258+
{
259+
(void)*format;
260+
(void)*tm;
261+
__CPROVER_havoc_slice(s, max);
262+
__CPROVER_size_t length = __VERIFIER_nondet_size_t();
263+
if(length >= max)
264+
return 0;
265+
s[length] = '\0';
266+
return length;
267+
}

0 commit comments

Comments
 (0)