diff --git a/matlab/swz/c-code/mex/mex_top_level.c b/matlab/swz/c-code/mex/mex_top_level.c index f070b0691..d66547b44 100644 --- a/matlab/swz/c-code/mex/mex_top_level.c +++ b/matlab/swz/c-code/mex/mex_top_level.c @@ -34,15 +34,15 @@ mexFunction(int nlhs, mxArray *plhs[], * Allocate memory */ maxnargs = (int)(mxGetN(prhs[0])/2+1); - argument = (char *)calloc(mxGetN(prhs[0])+1, sizeof(char)); - args = (char **)calloc(maxnargs, sizeof(char *)); + argument = (char *)swzCalloc(mxGetN(prhs[0])+1, sizeof(char)); + args = (char **)swzCalloc(maxnargs, sizeof(char *)); if (argument==NULL || args==NULL) mexErrMsgTxt("In swz_mex: could not allocate memory. (1)"); /* * Create argument string from prhs and parse to create args / nargs */ - if (!(args[nargs] = (char *)calloc(strlen(mainarg)+1, sizeof(char)))) + if (!(args[nargs] = (char *)swzCalloc(strlen(mainarg)+1, sizeof(char)))) mexErrMsgTxt("In swz_mex: could not allocate memory. (2)"); strncpy(args[nargs++], mainarg, strlen(mainarg)); @@ -52,7 +52,7 @@ mexFunction(int nlhs, mxArray *plhs[], beginarg = &argument[0]; while(n=strcspn(beginarg, " ")) { - if (!(args[nargs] = (char *)calloc(n+1, sizeof(char)))) + if (!(args[nargs] = (char *)swzCalloc(n+1, sizeof(char)))) mexErrMsgTxt("In swz_mex: could not allocate memory. (3)"); strncpy(args[nargs++], beginarg, n); beginarg += (isspace(beginarg[n]) || isblank(beginarg[n]) ? ++n : n); diff --git a/matlab/swz/c-code/mex/modify_for_mex.h b/matlab/swz/c-code/mex/modify_for_mex.h index 1766af105..05cecd208 100644 --- a/matlab/swz/c-code/mex/modify_for_mex.h +++ b/matlab/swz/c-code/mex/modify_for_mex.h @@ -25,12 +25,11 @@ extern int constant_seed; #define swz_fprintf_stdout mexPrintf -#undef calloc #undef realloc #undef free #define swzMalloc mxMalloc -#define calloc mxCalloc +#define swzCalloc mxCalloc #define realloc mxRealloc #define free mxFree @@ -38,4 +37,5 @@ extern int constant_seed; #else #define swz_fprintf_stdout printf #define swzMalloc malloc +#define swzCalloc calloc #endif diff --git a/matlab/swz/c-code/utilities/DWCcode/arrays/dw_array.c b/matlab/swz/c-code/utilities/DWCcode/arrays/dw_array.c index e3cdc648e..74b676329 100644 --- a/matlab/swz/c-code/utilities/DWCcode/arrays/dw_array.c +++ b/matlab/swz/c-code/utilities/DWCcode/arrays/dw_array.c @@ -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(), calloc() or realloc(). + have been created via a call to swzMalloc(), swzCalloc() or realloc(). Returns Returns one upon success and zero upon failure. @@ -361,7 +361,7 @@ 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(), calloc() or realloc(). If + was dynamically created via a call to swzMalloc(), swzCalloc() or realloc(). If this is not the case, then servere memory problems can result. */ static int dw_CopyString(void *d, void *s) diff --git a/matlab/swz/c-code/utilities/DWCcode/ascii/dw_ascii.c b/matlab/swz/c-code/utilities/DWCcode/ascii/dw_ascii.c index 66fb7133b..e0fd65151 100644 --- a/matlab/swz/c-code/utilities/DWCcode/ascii/dw_ascii.c +++ b/matlab/swz/c-code/utilities/DWCcode/ascii/dw_ascii.c @@ -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 calloc() and the + must either null or allocated with swzMalloc(), realloc(), or swzCalloc() and the calling routine is responsible for eventually freeing the memory if the return value is not null. diff --git a/matlab/swz/c-code/utilities/DWCcode/matrix/bmatrix_blas_lapack.c b/matlab/swz/c-code/utilities/DWCcode/matrix/bmatrix_blas_lapack.c index 33fe0dd89..51b249e2f 100644 --- a/matlab/swz/c-code/utilities/DWCcode/matrix/bmatrix_blas_lapack.c +++ b/matlab/swz/c-code/utilities/DWCcode/matrix/bmatrix_blas_lapack.c @@ -514,7 +514,7 @@ int bLU(int *p, PRECISION *x, int m, int n, int xt) int minmn = (m < n) ? m : n; - if(!(p2 = (lapack_int *)calloc(minmn, sizeof(lapack_int)))) + if(!(p2 = (lapack_int *)swzCalloc(minmn, sizeof(lapack_int)))) return MEM_ERR; for(i=0; i