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