Skip to content

Commit 9c704e8

Browse files
committed
Reimplement inside stdlib.c
will be squashed.
1 parent 0c2c362 commit 9c704e8

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

src/ansi-c/ansi_c_internal_additions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ void ansi_c_internal_additions(std::string &code)
155155
"void *" CPROVER_PREFIX "allocate("
156156
CPROVER_PREFIX "size_t size, " CPROVER_PREFIX "bool zero);\n"
157157
"const void *" CPROVER_PREFIX "alloca_object = 0;\n"
158+
CPROVER_PREFIX "size_t " CPROVER_PREFIX "pointer_width="+
159+
std::to_string(config.ansi_c.pointer_width)+";\n"
160+
CPROVER_PREFIX "size_t " CPROVER_PREFIX "object_bits="+
161+
std::to_string(config.bv_encoding.object_bits)+";\n"
158162

159163
// this is ANSI-C
160164
"extern " CPROVER_PREFIX "thread_local const char __func__["

src/ansi-c/library/cprover.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ extern const void *__CPROVER_malloc_object;
1616
extern __CPROVER_size_t __CPROVER_malloc_size;
1717
extern _Bool __CPROVER_malloc_is_new_array;
1818
extern const void *__CPROVER_memory_leak;
19+
extern __CPROVER_size_t __CPROVER_pointer_width;
20+
extern __CPROVER_size_t __CPROVER_object_bits;
1921

2022
void __CPROVER_assume(__CPROVER_bool assumption) __attribute__((__noreturn__));
2123
void __CPROVER_assert(__CPROVER_bool assertion, const char *description);

src/ansi-c/library/stdlib.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ inline void *malloc(__CPROVER_size_t malloc_size)
115115
// realistically, malloc may return NULL,
116116
// and __CPROVER_allocate doesn't, but no one cares
117117
__CPROVER_HIDE:;
118+
119+
if (malloc_size >= ((__CPROVER_size_t)1 << (__CPROVER_pointer_width - __CPROVER_object_bits)))
120+
return (void*)0;
121+
118122
void *malloc_res;
119123
malloc_res = __CPROVER_allocate(malloc_size, 0);
120124

0 commit comments

Comments
 (0)