SWZ: replace realloc with swzRealloc

time-shift
Houtan Bastani 2010-07-05 16:52:11 +02:00
parent 571f430085
commit bf38d85c04
3 changed files with 8 additions and 8 deletions

View File

@ -25,12 +25,11 @@ extern int constant_seed;
#define swz_fprintf_stdout mexPrintf
#undef realloc
#undef free
#define swzMalloc mxMalloc
#define swzCalloc mxCalloc
#define realloc mxRealloc
#define swzRealloc mxRealloc
#define free mxFree
@ -38,4 +37,5 @@ extern int constant_seed;
#define swz_fprintf_stdout printf
#define swzMalloc malloc
#define swzCalloc calloc
#define swzRealloc realloc
#endif

View File

@ -349,7 +349,7 @@ void* dw_CopyArray(void* d, void* s)
Assumes
Both d and s are valid pointers and both *d and *s are either null or a
null terminated string. If *d is a null terminated string, then it must
have been created via a call to swzMalloc(), swzCalloc() or realloc().
have been created via a call to swzMalloc(), swzCalloc() or swzRealloc().
Returns
Returns one upon success and zero upon failure.
@ -361,14 +361,14 @@ void* dw_CopyArray(void* d, void* s)
Notes
It is critical that this function be called only if the destination string
was dynamically created via a call to swzMalloc(), swzCalloc() or realloc(). If
was dynamically created via a call to swzMalloc(), swzCalloc() or swzRealloc(). If
this is not the case, then servere memory problems can result.
*/
static int dw_CopyString(void *d, void *s)
{
char* dest;
if (*((char**)s))
if (dest=realloc(*((char**)d),strlen(*((char**)s))+1))
if (dest=swzRealloc(*((char**)d),strlen(*((char**)s))+1))
strcpy(*((char**)d)=dest,*((char**)s));
else
return 0;

View File

@ -74,7 +74,7 @@ FILE *dw_AppendTextFile(char *filename)
the buffer containing the file and resets *n if necessary. The if the
passed buffer is null or is not large enough to contain the line, buffer is
freed and a new buffer is allocated. Because of this, the passed buffer
must either null or allocated with swzMalloc(), realloc(), or swzCalloc() and the
must either null or allocated with swzMalloc(), swzRealloc(), or swzCalloc() and the
calling routine is responsible for eventually freeing the memory if the
return value is not null.
@ -96,7 +96,7 @@ char* dw_ReadLine(FILE *f, char *buffer, int *n)
if (ptr[(i=(int)strlen(ptr))-1] == '\n')
return buffer;
else
if (!(nbuffer=(char*)realloc(buffer,*n+=SIZE_INCREMENT)))
if (!(nbuffer=(char*)swzRealloc(buffer,*n+=SIZE_INCREMENT)))
{
free(buffer);
*n=0;
@ -310,7 +310,7 @@ int dw_PrintDelimitedArray(FILE *f, void* array, char delimiter)
/* { */
/* //=== reallocate memory if necessary */
/* if (k+1 > *n) */
/* if (!(ptr=(char*)realloc(buffer,*n+=INCREMENT))) */
/* if (!(ptr=(char*)swzRealloc(buffer,*n+=INCREMENT))) */
/* { */
/* *n-=INCREMENT; */
/* return 0; */