mirror of
https://github.com/adtools/clib2.git
synced 2025-12-08 14:59:05 +00:00
- In libunix.a malloc(), calloc() and realloc() no longer treat a
request to allocate 0 bytes as an error, returning NULL. They all return a 1 byte memory chunk initialized to 0 instead. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@15064 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: stdlib_calloc.c,v 1.5 2005-03-18 12:38:23 obarthel Exp $
|
||||
* $Id: stdlib_calloc.c,v 1.6 2005-11-20 17:00:22 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -51,6 +51,7 @@ __static void *
|
||||
__calloc(size_t num_elements,size_t element_size,const char * file,int line)
|
||||
{
|
||||
void * result = NULL;
|
||||
size_t total_size;
|
||||
|
||||
#ifdef __MEM_DEBUG
|
||||
{
|
||||
@@ -58,24 +59,13 @@ __calloc(size_t num_elements,size_t element_size,const char * file,int line)
|
||||
}
|
||||
#endif /* __MEM_DEBUG */
|
||||
|
||||
assert( (int)num_elements >= 0 && (int)element_size >= 0 );
|
||||
total_size = num_elements * element_size;
|
||||
|
||||
if(num_elements > 0 && element_size > 0)
|
||||
{
|
||||
size_t total_size;
|
||||
|
||||
total_size = num_elements * element_size;
|
||||
|
||||
result = __malloc(total_size,file,line);
|
||||
if(result != NULL)
|
||||
memset(result,0,total_size);
|
||||
else
|
||||
SHOWMSG("memory allocation failure");
|
||||
}
|
||||
result = __malloc(total_size,file,line);
|
||||
if(result != NULL)
|
||||
memset(result,0,total_size);
|
||||
else
|
||||
{
|
||||
SHOWMSG("zero length allocation");
|
||||
}
|
||||
SHOWMSG("memory allocation failure");
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user