blob: 30b88b30e3dcd55cf0e994602c61b33ad06ebecb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
//===-- calloc.c ----------------------------------------------------------===//
//
// The KLEE Symbolic Virtual Machine
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <stdlib.h>
#include <string.h>
// DWD - I prefer to be internal
#if 0
void *calloc(size_t nmemb, size_t size) {
unsigned nbytes = nmemb * size;
void *addr = malloc(nbytes);
if(addr)
memset(addr, 0, nbytes);
return addr;
}
// Always reallocate.
void *realloc(void *ptr, size_t nbytes) {
if(!ptr)
return malloc(nbytes);
if(!nbytes) {
free(ptr);
return 0;
}
unsigned copy_nbytes = klee_get_obj_size(ptr);
//printf("REALLOC: current object = %d bytes!\n", copy_nbytes);
void *addr = malloc(nbytes);
if(addr) {
// shrinking
if(copy_nbytes > nbytes)
copy_nbytes = nbytes;
//printf("REALLOC: copying = %d bytes!\n", copy_nbytes);
memcpy(addr, ptr, copy_nbytes);
free(ptr);
}
return addr;
}
#endif
|