Add memory allocation checks for:
src/ciderlib src/xspice a few in src/frontend
This commit is contained in:
parent
a4ff5a204a
commit
9de2a2c1d5
|
|
@ -266,7 +266,7 @@ ONEbindCSC (ONEdevice *pDevice)
|
|||
BindStruct = pDevice->matrix->SMPkluMatrix->KLUmatrixBindStructForCIDER ;
|
||||
nz = pDevice->matrix->SMPkluMatrix->KLUmatrixNZ ;
|
||||
|
||||
BindStructCSC = (BindElementKLUforCIDER *) malloc (nz * sizeof (BindElementKLUforCIDER)) ;
|
||||
BindStructCSC = TMALLOC(BindElementKLUforCIDER, nz);
|
||||
for (index = 0 ; index < (int)nz ; index++) {
|
||||
BindStructCSC [index] = BindStruct [index] ;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ ONEQbindCSC (ONEdevice *pDevice)
|
|||
BindStruct = pDevice->matrix->SMPkluMatrix->KLUmatrixBindStructForCIDER ;
|
||||
nz = pDevice->matrix->SMPkluMatrix->KLUmatrixNZ ;
|
||||
|
||||
BindStructCSC = (BindElementKLUforCIDER *) malloc (nz * sizeof (BindElementKLUforCIDER)) ;
|
||||
BindStructCSC = TMALLOC (BindElementKLUforCIDER, nz) ;
|
||||
for (index = 0 ; index < (int)nz ; index++) {
|
||||
BindStructCSC [index] = BindStruct [index] ;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -905,7 +905,7 @@ TWObindCSC (TWOdevice *pDevice)
|
|||
BindStruct = pDevice->matrix->SMPkluMatrix->KLUmatrixBindStructForCIDER ;
|
||||
nz = pDevice->matrix->SMPkluMatrix->KLUmatrixNZ ;
|
||||
|
||||
BindStructCSC = (BindElementKLUforCIDER *) malloc (nz * sizeof (BindElementKLUforCIDER)) ;
|
||||
BindStructCSC = TMALLOC (BindElementKLUforCIDER, nz) ;
|
||||
for (index = 0 ; index < (int)nz ; index++) {
|
||||
BindStructCSC [index] = BindStruct [index] ;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -585,7 +585,7 @@ TWONbindCSC (TWOdevice *pDevice)
|
|||
BindStruct = pDevice->matrix->SMPkluMatrix->KLUmatrixBindStructForCIDER ;
|
||||
nz = pDevice->matrix->SMPkluMatrix->KLUmatrixNZ ;
|
||||
|
||||
BindStructCSC = (BindElementKLUforCIDER *) malloc (nz * sizeof (BindElementKLUforCIDER)) ;
|
||||
BindStructCSC = TMALLOC (BindElementKLUforCIDER, nz) ;
|
||||
for (index = 0 ; index < (int)nz ; index++) {
|
||||
BindStructCSC [index] = BindStruct [index] ;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -585,7 +585,7 @@ TWOPbindCSC (TWOdevice *pDevice)
|
|||
BindStruct = pDevice->matrix->SMPkluMatrix->KLUmatrixBindStructForCIDER ;
|
||||
nz = pDevice->matrix->SMPkluMatrix->KLUmatrixNZ ;
|
||||
|
||||
BindStructCSC = (BindElementKLUforCIDER *) malloc (nz * sizeof (BindElementKLUforCIDER)) ;
|
||||
BindStructCSC = TMALLOC (BindElementKLUforCIDER, nz) ;
|
||||
for (index = 0 ; index < (int)nz ; index++) {
|
||||
BindStructCSC [index] = BindStruct [index] ;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ TWOQbindCSC (TWOdevice *pDevice)
|
|||
BindStruct = pDevice->matrix->SMPkluMatrix->KLUmatrixBindStructForCIDER ;
|
||||
nz = pDevice->matrix->SMPkluMatrix->KLUmatrixNZ ;
|
||||
|
||||
BindStructCSC = (BindElementKLUforCIDER *) malloc (nz * sizeof (BindElementKLUforCIDER)) ;
|
||||
BindStructCSC = TMALLOC (BindElementKLUforCIDER, nz) ;
|
||||
for (index = 0 ; index < (int)nz ; index++) {
|
||||
BindStructCSC [index] = BindStruct [index] ;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1421,7 +1421,7 @@ static struct inp_read_t inp_read(FILE* fp, int call_depth, const char* dir_name
|
|||
}
|
||||
/* OK -- now we have loaded the next line into 'buffer'. Process it.
|
||||
*
|
||||
/* If input line is blank, ignore it & continue looping. */
|
||||
* If input line is blank, ignore it & continue looping. */
|
||||
if ((strcmp(buffer, "\n") == 0) || (strcmp(buffer, "\r\n") == 0))
|
||||
if (call_depth != 0 || (call_depth == 0 && cc != NULL)) {
|
||||
line_number_orig++;
|
||||
|
|
|
|||
|
|
@ -678,7 +678,7 @@ com_write(wordlist *wl)
|
|||
}
|
||||
}
|
||||
}
|
||||
end->v_next = NULL;
|
||||
if (end) end->v_next = NULL;
|
||||
|
||||
/* Maybe we shouldn't make sure that the default scale is
|
||||
* present if nobody uses it.
|
||||
|
|
@ -843,7 +843,7 @@ com_write_sparam(wordlist *wl)
|
|||
}
|
||||
}
|
||||
}
|
||||
end->v_next = NULL;
|
||||
if (end) end->v_next = NULL;
|
||||
|
||||
/* Maybe we shouldn't make sure that the default scale is
|
||||
* present if nobody uses it.
|
||||
|
|
|
|||
|
|
@ -67,9 +67,10 @@ typedef struct {
|
|||
} SSFILE;
|
||||
|
||||
static void* my_open_sf(char* fn, int nchannel) {
|
||||
SSFILE* d = calloc(1, sizeof(SSFILE));
|
||||
SSFILE* d;
|
||||
SF_INFO sfinfo;
|
||||
|
||||
XCALLOC(d, SSFILE, 1);
|
||||
sfinfo.samplerate = o_samplerate;
|
||||
sfinfo.channels = nchannel;
|
||||
sfinfo.frames = 0;
|
||||
|
|
@ -77,7 +78,7 @@ static void* my_open_sf(char* fn, int nchannel) {
|
|||
|
||||
d->sf_channels = nchannel;
|
||||
d->sf_bptr = 0;
|
||||
d->sf_buf = calloc(nchannel, sizeof(float));
|
||||
XCALLOC(d->sf_buf, float, nchannel);
|
||||
|
||||
if ((d->outfile = sf_open(fn, SFM_WRITE, &sfinfo)) == NULL) {
|
||||
fprintf(stderr, "Error: Not able to open output file '%s'\n", fn);
|
||||
|
|
@ -225,15 +226,15 @@ void snd_init(int nchannel) {
|
|||
if (!filename) snd_configure("spice.wav", 48000, o_sndfmt, o_mult, o_off, oversampling);
|
||||
outfile = p_open(filename, nchannel);
|
||||
sp_nchannel = nchannel;
|
||||
sp_buf = calloc(SP_MAX, sizeof(SP_BUF));
|
||||
XCALLOC(sp_buf, SP_BUF, SP_MAX);
|
||||
for (i = 0; i < SP_MAX; i++) {
|
||||
sp_buf[i].tme = 0.0;
|
||||
sp_buf[i].val = calloc(nchannel, sizeof(double));
|
||||
XCALLOC(sp_buf[i].val, double, nchannel);
|
||||
}
|
||||
sample = 0;
|
||||
#ifdef HAVE_SRC
|
||||
interleaved = calloc(nchannel * OBUFSIZE * oversampling, sizeof(float));
|
||||
resampled = calloc(nchannel * OBUFSIZE, sizeof(float));
|
||||
XCALLOC(interleaved, float, nchannel * OBUFSIZE * oversampling);
|
||||
XCALLOC(resampled, float, nchannel * OBUFSIZE);
|
||||
rabbit = src_new(SRC_SINC_BEST_QUALITY, nchannel, &rabbit_err);
|
||||
src_set_ratio(rabbit, 1.0 / OVERSAMPLING);
|
||||
src_reset(rabbit);
|
||||
|
|
|
|||
|
|
@ -1050,7 +1050,7 @@ bxx_printf(struct bxx_buffer *t, const char *fmt, ...)
|
|||
}
|
||||
}
|
||||
|
||||
va_end(ap);
|
||||
// va_end(ap); /* already matched with va_start in for loop */
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -98,20 +98,20 @@ enum ALL_TYPE_ENUM {
|
|||
static enum ALL_TYPE_ENUM get_all_type(const char *word)
|
||||
{
|
||||
/* Check for start of "all" */
|
||||
if (tolower(word[0] != 'a')) {
|
||||
if (word[0] == '\0' || tolower(word[0]) != 'a') {
|
||||
return ALL_TYPE_NONE;
|
||||
}
|
||||
if (tolower(word[1] != 'l')) {
|
||||
if (word[1] == '\0' || tolower(word[1]) != 'l') {
|
||||
return ALL_TYPE_NONE;
|
||||
}
|
||||
if (tolower(word[2] != 'l')) {
|
||||
if (word[2] == '\0' || tolower(word[2]) != 'l') {
|
||||
return ALL_TYPE_NONE;
|
||||
}
|
||||
|
||||
if (word[3] == '\0') {
|
||||
return ALL_TYPE_ALL;
|
||||
}
|
||||
/* It may be some type of all */
|
||||
switch (tolower(word[3])) {
|
||||
case '\0':
|
||||
return ALL_TYPE_ALL;
|
||||
case 'v':
|
||||
if (word[4] == '\0') {
|
||||
return ALL_TYPE_ALLV;
|
||||
|
|
@ -142,7 +142,7 @@ static enum ALL_TYPE_ENUM get_all_type(const char *word)
|
|||
}
|
||||
default:
|
||||
return ALL_TYPE_NONE;
|
||||
} /* end of swith over char after "all" */
|
||||
} /* end of switch over char after "all" */
|
||||
} /* end of function get_all_type */
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@ void cm_astate(ARGS)
|
|||
sizeof(stLocal_Data_t)))) == (stLocal_Data_t *) NULL) {
|
||||
cm_message_send("Unable to allocate Local_Data_t "
|
||||
"in cm_astate()");
|
||||
cm_cexit(1);
|
||||
return;
|
||||
}
|
||||
loc->state1 = 0;
|
||||
|
|
|
|||
|
|
@ -131,6 +131,7 @@ void cm_delay(ARGS)
|
|||
sizeof(mLocal_Data_t)))) == (mLocal_Data_t *) NULL) {
|
||||
cm_message_send("Unable to allocate Local_Data_t "
|
||||
"in cm_delay()");
|
||||
cm_cexit(1);
|
||||
return;
|
||||
}
|
||||
/*** allocate static storage for the delay buffer ***/
|
||||
|
|
@ -138,6 +139,7 @@ void cm_delay(ARGS)
|
|||
if (loc->buffer == (double *) NULL) {
|
||||
cm_message_send("Unable to allocate delay buffer "
|
||||
"in cm_delay()");
|
||||
cm_cexit(1);
|
||||
return;
|
||||
}
|
||||
loc->buffer_size = buffer_size;
|
||||
|
|
|
|||
|
|
@ -268,6 +268,10 @@ static char *CNVgettok(char **s)
|
|||
/* allocate space big enough for the whole string */
|
||||
|
||||
buf = (char *) malloc(strlen(*s) + 1);
|
||||
if (!buf) {
|
||||
cm_message_send("cannot allocate enough memory in file_source");
|
||||
cm_cexit(1);
|
||||
}
|
||||
|
||||
/* skip over any white space */
|
||||
|
||||
|
|
@ -311,6 +315,10 @@ static char *CNVgettok(char **s)
|
|||
|
||||
|
||||
ret_str = (char *) malloc(strlen(buf) + 1);
|
||||
if (!ret_str) {
|
||||
cm_message_send("cannot allocate enough memory in file_source");
|
||||
cm_cexit(1);
|
||||
}
|
||||
ret_str = strcpy(ret_str,buf);
|
||||
|
||||
if(buf) free(buf);
|
||||
|
|
@ -397,6 +405,7 @@ void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc.
|
|||
sizeof(Local_Data_t)))) == (Local_Data_t *) NULL) {
|
||||
cm_message_send("Unable to allocate Local_Data_t "
|
||||
"in cm_filesource()");
|
||||
cm_cexit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -408,6 +417,10 @@ void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc.
|
|||
sizeof(struct filesource_state)); /* calloc to null fp */
|
||||
loc->indata = (struct infiledata *) malloc(
|
||||
sizeof(struct infiledata));
|
||||
if (!loc->indata) {
|
||||
cm_message_send("cannot allocate enough memory in file_source");
|
||||
cm_cexit(1);
|
||||
}
|
||||
loc->indata->datavec = (double *) malloc(sizeof(double) *
|
||||
(size_t) (stepsize * 1000));
|
||||
|
||||
|
|
@ -415,10 +428,10 @@ void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc.
|
|||
if (loc->timeinterval == (double *) NULL ||
|
||||
loc->amplinterval == (double *) NULL ||
|
||||
loc->state == (struct filesource_state *) NULL ||
|
||||
loc->indata == (struct infiledata *) NULL ||
|
||||
loc->indata->datavec == (double *) NULL) {
|
||||
cm_message_send("Unable to allocate Local_Data_t fields "
|
||||
"in cm_filesource()");
|
||||
cm_cexit(1);
|
||||
cm_filesource_callback(mif_private, MIF_CB_DESTROY);
|
||||
return;
|
||||
}
|
||||
|
|
@ -443,6 +456,7 @@ void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc.
|
|||
(char *) NULL) {
|
||||
cm_message_send("Unable to allocate buffer "
|
||||
"for building file name in cm_filesource()");
|
||||
cm_cexit(1);
|
||||
}
|
||||
else {
|
||||
sprintf(p, "%s%s%s", lbuffer, DIR_PATHSEP, PARAM(file));
|
||||
|
|
@ -464,7 +478,6 @@ void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc.
|
|||
while (!loc->state->atend) {
|
||||
char line[512];
|
||||
char *cp, *cpdel;
|
||||
char *cp2;
|
||||
double t = 0, d = 0;
|
||||
int i;
|
||||
if (!fgets(line, sizeof(line), loc->state->fp)) {
|
||||
|
|
@ -513,7 +526,9 @@ void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc.
|
|||
void * const p = realloc(loc->indata->datavec,
|
||||
sizeof(double) * loc->indata->vecallocated);
|
||||
if (p == NULL) {
|
||||
cm_message_printf("cannot allocate enough memory");
|
||||
cm_message_send("cannot allocate enough memory"
|
||||
" in file_source");
|
||||
cm_cexit(1);
|
||||
break; // loc->state->atend = 1;
|
||||
}
|
||||
loc->indata->datavec = (double *) p;
|
||||
|
|
@ -524,10 +539,10 @@ void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc.
|
|||
for (i = 0; i < size; ++i) {
|
||||
while (*cp && (isspace_c(*cp) || *cp == ','))
|
||||
++cp;
|
||||
char *ncp = CNVgettok(&cp);
|
||||
int ret = cnv_get_spice_value(ncp, &d);
|
||||
free(ncp);
|
||||
if (ret == FAIL) {
|
||||
char *nncp = CNVgettok(&cp);
|
||||
int rret = cnv_get_spice_value(nncp, &d);
|
||||
free(nncp);
|
||||
if (rret == FAIL) {
|
||||
derr = MIF_TRUE;
|
||||
break;
|
||||
}
|
||||
|
|
@ -550,9 +565,9 @@ void cm_filesource(ARGS) /* structure holding parms, inputs, outputs, etc.
|
|||
loc->timeinterval[1] = loc->indata->datavec[loc->indata->actpointer + stepsize];
|
||||
|
||||
if (terr)
|
||||
cm_message_printf("WARNING: some error occurred during reading the time values");
|
||||
cm_message_send("WARNING: some error occurred during reading the time values");
|
||||
if (derr)
|
||||
cm_message_printf("WARNING: some error occurred during reading the data values");
|
||||
cm_message_send("WARNING: some error occurred during reading the data values");
|
||||
}
|
||||
|
||||
loc = STATIC_VAR (locdata);
|
||||
|
|
|
|||
|
|
@ -270,17 +270,24 @@ void cm_oneshot(ARGS) /* structure holding parms,
|
|||
/*** allocate static storage for *loc ***/
|
||||
STATIC_VAR (locdata) = calloc (1 , sizeof ( Local_Data_t ));
|
||||
loc = STATIC_VAR (locdata);
|
||||
if (!loc) {
|
||||
cm_message_send(oneshot_allocation_error);
|
||||
cm_cexit(1);
|
||||
return;
|
||||
}
|
||||
CALLBACK = oneshot_callback;
|
||||
|
||||
/* Allocate storage for breakpoint domain & pulse width values */
|
||||
x = loc->control = (double *) calloc((size_t) cntl_size, sizeof(double));
|
||||
if (!x) {
|
||||
cm_message_send(oneshot_allocation_error);
|
||||
cm_cexit(1);
|
||||
return;
|
||||
}
|
||||
y = loc->pw = (double *) calloc((size_t) pw_size, sizeof(double));
|
||||
if (!y) {
|
||||
cm_message_send(oneshot_allocation_error);
|
||||
cm_cexit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -277,7 +277,7 @@ void cm_pwl(ARGS) /* structure holding parms,
|
|||
|
||||
CALLBACK = cm_pwl_callback;
|
||||
|
||||
char *allocation_error="\n***ERROR***\nPWL: Allocation calloc failed!\n";
|
||||
char *allocation_error="\n***ERROR***\nPWL: Allocation malloc/calloc failed!\n";
|
||||
char *limit_error="\n***ERROR***\nPWL: Violation of 50% rule in breakpoints!\n";
|
||||
|
||||
/* Retrieve frequently used parameters... */
|
||||
|
|
@ -299,18 +299,24 @@ void cm_pwl(ARGS) /* structure holding parms,
|
|||
/* Allocate storage for last_x_value */
|
||||
STATIC_VAR(last_x_value) = (double *) malloc(sizeof(double));
|
||||
last_x_value = (double *) STATIC_VAR(last_x_value);
|
||||
if (!last_x_value) {
|
||||
cm_message_send(allocation_error);
|
||||
cm_cexit(1);
|
||||
}
|
||||
|
||||
/* Allocate storage for breakpoint domain & range values */
|
||||
STATIC_VAR(x) = (double *) calloc((size_t) size, sizeof(double));
|
||||
x = (double *) STATIC_VAR(x);
|
||||
if (!x) {
|
||||
cm_message_send(allocation_error);
|
||||
cm_cexit(1);
|
||||
}
|
||||
|
||||
STATIC_VAR(y) = (double *) calloc((size_t) size, sizeof(double));
|
||||
y = (double *) STATIC_VAR(y);
|
||||
if (!y) {
|
||||
cm_message_send(allocation_error);
|
||||
cm_cexit(1);
|
||||
}
|
||||
|
||||
/* Retrieve x and y values. */
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ void cm_pwlts(ARGS) /* structure holding parms,
|
|||
|
||||
CALLBACK = cm_pwlts_callback;
|
||||
|
||||
char *allocation_error="\n***ERROR***\nPWL: Allocation calloc failed!\n";
|
||||
char *allocation_error="\n***ERROR***\nPWL: Allocation malloc/calloc failed!\n";
|
||||
char *limit_error="\n***ERROR***\nPWL: Violation of 50% rule in breakpoints!\n";
|
||||
|
||||
/* Retrieve frequently used parameters... */
|
||||
|
|
@ -180,18 +180,24 @@ void cm_pwlts(ARGS) /* structure holding parms,
|
|||
/* Allocate storage for last_x_value */
|
||||
STATIC_VAR(last_x_value) = (double *) malloc(sizeof(double));
|
||||
last_x_value = (double *) STATIC_VAR(last_x_value);
|
||||
if (!last_x_value) {
|
||||
cm_message_send(allocation_error);
|
||||
cm_cexit(1);
|
||||
}
|
||||
|
||||
/* Allocate storage for breakpoint domain & range values */
|
||||
STATIC_VAR(x) = (double *) calloc((size_t) size, sizeof(double));
|
||||
x = (double *) STATIC_VAR(x);
|
||||
if (!x) {
|
||||
cm_message_send(allocation_error);
|
||||
cm_cexit(1);
|
||||
}
|
||||
|
||||
STATIC_VAR(y) = (double *) calloc((size_t) size, sizeof(double));
|
||||
y = (double *) STATIC_VAR(y);
|
||||
if (!y) {
|
||||
cm_message_send(allocation_error);
|
||||
cm_cexit(1);
|
||||
}
|
||||
|
||||
/* Retrieve x and y values. */
|
||||
|
|
|
|||
|
|
@ -64,8 +64,12 @@ NON-STANDARD FEATURES
|
|||
|
||||
|
||||
/*=== MACROS ===========================*/
|
||||
|
||||
|
||||
#define CHECK_ALLOC(p) { \
|
||||
if (!p) { \
|
||||
cm_message_send("out of memory in s_xfer"); \
|
||||
cm_cexit(1); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
/*=== LOCAL VARIABLES & TYPEDEFS =======*/
|
||||
|
|
@ -281,15 +285,21 @@ void cm_s_xfer(ARGS) /* structure holding parms, inputs, outputs, etc. */
|
|||
are not functional */
|
||||
|
||||
integrator = (double **) calloc((size_t) den_size, sizeof(double *));
|
||||
CHECK_ALLOC(integrator);
|
||||
old_integrator = (double **) calloc((size_t) den_size, sizeof(double *));
|
||||
CHECK_ALLOC(old_integrator);
|
||||
|
||||
/* Allocate storage for coefficient values */
|
||||
|
||||
den_coefficient = (double **) calloc((size_t) den_size, sizeof(double *));
|
||||
CHECK_ALLOC(den_coefficient);
|
||||
old_den_coefficient = (double **) calloc((size_t) den_size, sizeof(double *));
|
||||
CHECK_ALLOC(old_den_coefficient);
|
||||
|
||||
num_coefficient = (double **) calloc((size_t) num_size, sizeof(double *));
|
||||
CHECK_ALLOC(num_coefficient);
|
||||
old_num_coefficient = (double **) calloc((size_t) num_size, sizeof(double *));
|
||||
CHECK_ALLOC(old_num_coefficient);
|
||||
|
||||
for (i=0; i < (2*den_size + num_size + 3); i++)
|
||||
cm_analog_alloc(i,sizeof(double));
|
||||
|
|
@ -297,6 +307,7 @@ void cm_s_xfer(ARGS) /* structure holding parms, inputs, outputs, etc. */
|
|||
/* ITP_VAR_SIZE(den) = den_size; */
|
||||
|
||||
/* gain = (double *) calloc(1,sizeof(double));
|
||||
CHECK_ALLOC(gain);
|
||||
ITP_VAR(total_gain) = gain;
|
||||
ITP_VAR_SIZE(total_gain) = 1.0; */
|
||||
|
||||
|
|
@ -327,7 +338,9 @@ void cm_s_xfer(ARGS) /* structure holding parms, inputs, outputs, etc. */
|
|||
/* Set pointers to storage locations for in, out, and integrators...*/
|
||||
|
||||
integrator = (double **) calloc((size_t) den_size, sizeof(double *));
|
||||
CHECK_ALLOC(integrator);
|
||||
old_integrator = (double **) calloc((size_t) den_size, sizeof(double *));
|
||||
CHECK_ALLOC(old_integrator);
|
||||
|
||||
for (i=0; i<den_size; i++) {
|
||||
integrator[i] = (double *) cm_analog_get_ptr(i,0);
|
||||
|
|
@ -342,7 +355,9 @@ void cm_s_xfer(ARGS) /* structure holding parms, inputs, outputs, etc. */
|
|||
/* for denominator coefficients & gain... */
|
||||
|
||||
old_den_coefficient = (double **) calloc((size_t) den_size, sizeof(double *));
|
||||
CHECK_ALLOC(old_den_coefficient);
|
||||
den_coefficient = (double **) calloc((size_t) den_size, sizeof(double *));
|
||||
CHECK_ALLOC(den_coefficient);
|
||||
|
||||
for(i=den_size;i<2*den_size;i++){
|
||||
old_den_coefficient[i-den_size] = (double *) cm_analog_get_ptr(i,1);
|
||||
|
|
@ -351,7 +366,9 @@ void cm_s_xfer(ARGS) /* structure holding parms, inputs, outputs, etc. */
|
|||
}
|
||||
|
||||
num_coefficient = (double **) calloc((size_t) num_size, sizeof(double *));
|
||||
CHECK_ALLOC(num_coefficient);
|
||||
old_num_coefficient = (double **) calloc((size_t) num_size, sizeof(double *));
|
||||
CHECK_ALLOC(old_num_coefficient);
|
||||
|
||||
for(i=2*den_size;i<2*den_size+num_size;i++){
|
||||
old_num_coefficient[i-2*den_size] = (double *) cm_analog_get_ptr(i,1);
|
||||
|
|
|
|||
|
|
@ -91,8 +91,11 @@ static double *read_file(const char *fn, int span, int offset,
|
|||
|
||||
size = ALLOC;
|
||||
file_data = malloc(size * sizeof(double));
|
||||
if (!file_data)
|
||||
if (!file_data) {
|
||||
cm_message_send("out of memory in xfer");
|
||||
cm_cexit(1);
|
||||
goto bad;
|
||||
}
|
||||
want = skip = i = 0;
|
||||
|
||||
while (fgets(buff, sizeof buff, fp)) {
|
||||
|
|
@ -129,8 +132,11 @@ static double *read_file(const char *fn, int span, int offset,
|
|||
if (i + 9 > size) {
|
||||
size += ALLOC;
|
||||
file_data = realloc(file_data, size * sizeof(double));
|
||||
if (!file_data)
|
||||
if (!file_data) {
|
||||
cm_message_send("out of memory in xfer");
|
||||
cm_cexit(1);
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
|
||||
while (j < count) {
|
||||
|
|
@ -251,18 +257,26 @@ void cm_xfer(ARGS) /* structure holding parms, inputs, outputs, etc. */
|
|||
/* Allocate the internal table. */
|
||||
|
||||
table = (struct data *)malloc(sizeof(struct data));
|
||||
if (!table)
|
||||
if (!table) {
|
||||
cm_message_send("out of memory in xfer");
|
||||
cm_cexit(1);
|
||||
return;
|
||||
}
|
||||
table->size = size;
|
||||
table->f = (double*)malloc(size * sizeof (double));
|
||||
/* no need for frees when out of memory */
|
||||
if (!table->f) {
|
||||
free(table);
|
||||
//free(table);
|
||||
cm_message_send("out of memory in xfer");
|
||||
cm_cexit(1);
|
||||
return;
|
||||
}
|
||||
table->s = ( Mif_Complex_t *)malloc(size * sizeof (Mif_Complex_t));
|
||||
if (!table->s) {
|
||||
free(table->f);
|
||||
free(table);
|
||||
//free(table->f);
|
||||
//free(table);
|
||||
cm_message_send("out of memory in xfer");
|
||||
cm_cexit(1);
|
||||
return;
|
||||
}
|
||||
STATIC_VAR(table) = table;
|
||||
|
|
|
|||
|
|
@ -184,6 +184,10 @@ void cm_d_genlut(ARGS)
|
|||
/* allocate storage for the lookup table */
|
||||
STATIC_VAR (locdata) = calloc((size_t) tablelen, sizeof(Digital_t));
|
||||
lookup_table = STATIC_VAR (locdata);
|
||||
if (!lookup_table) {
|
||||
cm_message_send("out of memory in d_genlut");
|
||||
cm_cexit(1);
|
||||
}
|
||||
CALLBACK = genlut_callback;
|
||||
|
||||
/* allocate storage for the outputs */
|
||||
|
|
|
|||
|
|
@ -150,6 +150,10 @@ void cm_d_lut(ARGS)
|
|||
/* allocate storage for the lookup table */
|
||||
STATIC_VAR (locdata) = calloc((size_t) tablelen, sizeof(Digital_State_t));
|
||||
lookup_table = STATIC_VAR (locdata);
|
||||
if (!lookup_table) {
|
||||
cm_message_send("out of memory in d_lut");
|
||||
cm_cexit(1);
|
||||
}
|
||||
CALLBACK = lut_callback;
|
||||
|
||||
/* allocate storage for the outputs */
|
||||
|
|
|
|||
|
|
@ -94,8 +94,11 @@ void cm_d_osc(ARGS)
|
|||
|
||||
table = malloc(csize * sizeof (struct pwl));
|
||||
STATIC_VAR(locdata) = table;
|
||||
if (!table)
|
||||
if (!table) {
|
||||
cm_message_send("out of memory in d_osc");
|
||||
cm_cexit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < csize; ++i) {
|
||||
table[i].ctl = PARAM(cntl_array[i]);
|
||||
|
|
|
|||
|
|
@ -285,12 +285,14 @@ static int start(char *system_command, char * c_argv[], Process_t * process)
|
|||
filename_in = (char *) calloc(1, syscmd_len + 5);
|
||||
if (!filename_in) {
|
||||
cm_message_send("ERROR: No memory");
|
||||
cm_cexit(1);
|
||||
return 1;
|
||||
}
|
||||
filename_out = (char *) calloc(1, syscmd_len + 5);
|
||||
if (!filename_out) {
|
||||
free(filename_in);
|
||||
cm_message_send("ERROR: No memory");
|
||||
cm_cexit(1);
|
||||
return 1;
|
||||
}
|
||||
filename_in[0] = '\0';
|
||||
|
|
|
|||
|
|
@ -102,8 +102,11 @@ void cm_d_pwm(ARGS)
|
|||
|
||||
table = malloc(csize * sizeof (struct pwl));
|
||||
STATIC_VAR(locdata) = table;
|
||||
if (!table)
|
||||
if (!table) {
|
||||
cm_message_send("out of memory in d_pwm");
|
||||
cm_cexit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < csize; ++i) {
|
||||
table[i].ctl = PARAM(cntl_array[i]);
|
||||
|
|
|
|||
|
|
@ -72,6 +72,13 @@ NON-STANDARD FEATURES
|
|||
#define DIR_PATHSEP "/"
|
||||
#endif
|
||||
|
||||
#define CHECK_ALLOC(p) { \
|
||||
if (!p) { \
|
||||
cm_message_send("out of memory in d_source"); \
|
||||
cm_cexit(1); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
/*=== LOCAL VARIABLES & TYPEDEFS =======*/
|
||||
|
||||
|
|
@ -171,6 +178,7 @@ static char *CNVgettok(char **s)
|
|||
/* allocate space big enough for the whole string */
|
||||
|
||||
buf = (char *) malloc(strlen(*s) + 1);
|
||||
CHECK_ALLOC(buf);
|
||||
|
||||
/* skip over any white space */
|
||||
|
||||
|
|
@ -214,6 +222,7 @@ static char *CNVgettok(char **s)
|
|||
|
||||
|
||||
ret_str = (char *) malloc(strlen(buf) + 1);
|
||||
CHECK_ALLOC(ret_str);
|
||||
ret_str = strcpy(ret_str,buf);
|
||||
|
||||
if(buf) free(buf);
|
||||
|
|
@ -758,6 +767,7 @@ static int cm_read_source(FILE *source, Local_Data_t *loc)
|
|||
|
||||
/* set storage space for bits in a row and set them to 0*/
|
||||
loc->all_data[i] = (char*)malloc(sizeof(char) * (size_t) loc->width);
|
||||
CHECK_ALLOC(loc->all_data[i]);
|
||||
loc->imal = i;
|
||||
for (n = 0; n < loc->width; n++)
|
||||
loc->all_data[i][n] = 0;
|
||||
|
|
@ -956,6 +966,7 @@ void cm_d_source(ARGS)
|
|||
lbuffer = getenv("NGSPICE_INPUT_DIR");
|
||||
if (lbuffer && *lbuffer) {
|
||||
p = (char*) malloc(strlen(lbuffer) + strlen(DIR_PATHSEP) + strlen(PARAM(input_file)) + 1);
|
||||
CHECK_ALLOC(p);
|
||||
sprintf(p, "%s%s%s", lbuffer, DIR_PATHSEP, PARAM(input_file));
|
||||
source = fopen(p, "r");
|
||||
free(p);
|
||||
|
|
@ -981,6 +992,7 @@ void cm_d_source(ARGS)
|
|||
/*** allocate static storage for *loc ***/
|
||||
STATIC_VAR (locdata) = calloc (1 , sizeof ( Local_Data_t ));
|
||||
loc = STATIC_VAR (locdata);
|
||||
CHECK_ALLOC(loc);
|
||||
CALLBACK = cm_d_source_callback;
|
||||
|
||||
/*** allocate storage for *index, *bits & *timepoint ***/
|
||||
|
|
@ -1005,7 +1017,9 @@ void cm_d_source(ARGS)
|
|||
|
||||
/*** allocate storage for **all_data, & *all_timepoints ***/
|
||||
loc->all_timepoints = (double*)calloc((size_t) i, sizeof(double));
|
||||
CHECK_ALLOC(loc->all_timepoints);
|
||||
loc->all_data = (char**)calloc((size_t) i, sizeof(char*));
|
||||
CHECK_ALLOC(loc->all_data);
|
||||
|
||||
/* Send file pointer and the two array storage pointers */
|
||||
/* to "cm_read_source()". This will return after */
|
||||
|
|
|
|||
|
|
@ -66,6 +66,12 @@ NON-STANDARD FEATURES
|
|||
#define FAIL 1
|
||||
|
||||
/*=== MACROS ===========================*/
|
||||
#define CHECK_ALLOC(p) { \
|
||||
if (!p) { \
|
||||
cm_message_send("out of memory in d_state"); \
|
||||
cm_cexit(1); \
|
||||
} \
|
||||
}
|
||||
|
||||
/*=== LOCAL VARIABLES & TYPEDEFS =======*/
|
||||
|
||||
|
|
@ -183,6 +189,7 @@ static char *CNVgettok(char **s)
|
|||
/* allocate space big enough for the whole string */
|
||||
|
||||
buf = (char *) malloc(strlen(*s) + 1);
|
||||
CHECK_ALLOC(buf);
|
||||
|
||||
/* skip over any white space */
|
||||
|
||||
|
|
@ -226,6 +233,7 @@ static char *CNVgettok(char **s)
|
|||
|
||||
|
||||
ret_str = (char *) malloc(strlen(buf) + 1);
|
||||
CHECK_ALLOC(ret_str);
|
||||
ret_str = strcpy(ret_str,buf);
|
||||
|
||||
if(buf) free(buf);
|
||||
|
|
@ -1707,6 +1715,7 @@ void cm_d_state(ARGS)
|
|||
|
||||
/* Allocate storage for the state transition table. */
|
||||
table = calloc(1, sizeof (State_Table_t));
|
||||
CHECK_ALLOC(table);
|
||||
STATIC_VAR(table) = table;
|
||||
|
||||
/* increment counter if not a comment until EOF reached... */
|
||||
|
|
@ -1732,14 +1741,18 @@ void cm_d_state(ARGS)
|
|||
|
||||
/* Assign storage for arrays to pointers in state table. */
|
||||
table->state = (int *)calloc((size_t) (table->depth + 1), sizeof(int));
|
||||
CHECK_ALLOC(table->state);
|
||||
table->bits =(short *)calloc(
|
||||
(size_t)(table->num_outputs * table->depth / 4 + 1),
|
||||
sizeof (short));
|
||||
CHECK_ALLOC(table->bits);
|
||||
table->inputs = (short *)calloc(
|
||||
(size_t)(table->num_inputs * table->depth / 8 + 1),
|
||||
sizeof (short));
|
||||
CHECK_ALLOC(table->inputs);
|
||||
table->next_state = (int *)calloc((size_t)(table->depth + 1),
|
||||
sizeof (int));
|
||||
CHECK_ALLOC(table->next_state);
|
||||
CALLBACK = callback; // To free those allocations.
|
||||
|
||||
/*** allocate storage for *states... ***/
|
||||
|
|
|
|||
|
|
@ -118,6 +118,10 @@ void spice2poly (ARGS)
|
|||
Mif_Inst_Var_Data_t *p = STATIC_VAR_INST(acgains);
|
||||
p -> size = num_inputs;
|
||||
p -> element = (Mif_Value_t *) malloc((size_t) num_inputs * sizeof(Mif_Value_t));
|
||||
if (!p->element) {
|
||||
cm_message_send("out of memory in spice2poly");
|
||||
cm_cexit(1);
|
||||
}
|
||||
for(i = 0; i < num_inputs; i++)
|
||||
STATIC_VAR(acgains[i]) = 0.0;
|
||||
}
|
||||
|
|
@ -136,18 +140,30 @@ void spice2poly (ARGS)
|
|||
/* Get input values and coefficients to local storage for faster access */
|
||||
|
||||
in = (double *) malloc((size_t) num_inputs * sizeof(double));
|
||||
if (!in) {
|
||||
cm_message_send("out of memory in spice2poly");
|
||||
cm_cexit(1);
|
||||
}
|
||||
for(i = 0; i < num_inputs; i++)
|
||||
in[i] = INPUT(in[i]);
|
||||
|
||||
num_coefs = PARAM_SIZE(coef);
|
||||
|
||||
coef = (double *) malloc((size_t) num_coefs * sizeof(double));
|
||||
if (!coef) {
|
||||
cm_message_send("out of memory in spice2poly");
|
||||
cm_cexit(1);
|
||||
}
|
||||
for(i = 0; i < num_coefs; i++)
|
||||
coef[i] = PARAM(coef[i]);
|
||||
|
||||
|
||||
/* Allocate the array of exponents used in computing the poly terms */
|
||||
exp = (int *) malloc((size_t) num_inputs * sizeof(int));
|
||||
if (!exp) {
|
||||
cm_message_send("out of memory in spice2poly");
|
||||
cm_cexit(1);
|
||||
}
|
||||
|
||||
/* Initialize the exponents to zeros */
|
||||
for(i = 0; i < num_inputs; i++)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,12 @@ is returned. The original input string is undisturbed.
|
|||
|
||||
#include "gettokens.h"
|
||||
|
||||
#define CHECK_ALLOC(p) { \
|
||||
if (!p) { \
|
||||
cm_message_send("out of memory in gettokens"); \
|
||||
cm_cexit(1); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
char *CNVgettok(char **s)
|
||||
|
|
@ -27,6 +33,7 @@ char *CNVgettok(char **s)
|
|||
/* allocate space big enough for the whole string */
|
||||
|
||||
buf = (char *) malloc(strlen(*s) + 1);
|
||||
CHECK_ALLOC(buf);
|
||||
|
||||
/* skip over any white space */
|
||||
|
||||
|
|
@ -71,6 +78,7 @@ char *CNVgettok(char **s)
|
|||
|
||||
|
||||
ret_str = (char *) malloc(strlen(buf) + 1);
|
||||
CHECK_ALLOC(ret_str);
|
||||
ret_str = strcpy(ret_str,buf);
|
||||
|
||||
if (buf) free(buf);
|
||||
|
|
|
|||
|
|
@ -192,6 +192,10 @@ void cm_pswitch(ARGS) /* structure holding parms,
|
|||
/*** allocate static storage for *loc ***/
|
||||
STATIC_VAR (locdata) = calloc (1 , sizeof ( Local_Data_t ));
|
||||
loc = STATIC_VAR (locdata);
|
||||
if (!loc) {
|
||||
cm_message_send("out of memory in pswitch");
|
||||
cm_cexit(1);
|
||||
}
|
||||
|
||||
loc->cntl_on = cntl_on;
|
||||
loc->cntl_off = cntl_off;
|
||||
|
|
|
|||
|
|
@ -202,12 +202,14 @@ void cm_seegen(ARGS) /* structure holding parms,
|
|||
CALLBACK = cm_seegen_callback;
|
||||
|
||||
if (have_scaled) {
|
||||
int j;
|
||||
double del = 1e12;
|
||||
|
||||
cm_message_send("Use the scaling option\n");
|
||||
|
||||
allpulses = STATIC_VAR(pulses) = (pulse_info_t *) malloc(ports * sizeof(pulse_info_t));
|
||||
if (!allpulses) {
|
||||
cm_message_send("out of memory in seegenerator");
|
||||
cm_cexit(1);
|
||||
}
|
||||
|
||||
/* parameter inull not specified, calculate it */
|
||||
if (inull == 0) {
|
||||
|
|
@ -237,6 +239,10 @@ void cm_seegen(ARGS) /* structure holding parms,
|
|||
/* Allocate storage for last_t_value */
|
||||
STATIC_VAR(last_t_value) = (double *) malloc(sizeof(double));
|
||||
last_t_value = (double *) STATIC_VAR(last_t_value);
|
||||
if (!last_t_value) {
|
||||
cm_message_send("out of memory in seegenerator");
|
||||
cm_cexit(1);
|
||||
}
|
||||
/* no start if ctrl is set */
|
||||
if (PORT_NULL(ctrl))
|
||||
*last_t_value = tdelay;
|
||||
|
|
@ -244,9 +250,17 @@ void cm_seegen(ARGS) /* structure holding parms,
|
|||
*last_t_value = 1e12;
|
||||
STATIC_VAR(last_ctrl) = (double *) malloc(sizeof(double));
|
||||
last_ctrl = (double *) STATIC_VAR(last_ctrl);
|
||||
if (!last_ctrl) {
|
||||
cm_message_send("out of memory in seegenerator");
|
||||
cm_cexit(1);
|
||||
}
|
||||
*last_ctrl = ctrl;
|
||||
STATIC_VAR(pulse_number) = (int *) malloc(sizeof(int));
|
||||
pulse_number = (int *) STATIC_VAR(pulse_number);
|
||||
if (!pulse_number) {
|
||||
cm_message_send("out of memory in seegenerator");
|
||||
cm_cexit(1);
|
||||
}
|
||||
*pulse_number = 1;
|
||||
|
||||
/* set breakpoints at first pulse start and pulse maximum times */
|
||||
|
|
|
|||
|
|
@ -140,6 +140,10 @@ void cm_sidiode(ARGS) /* structure holding parms,
|
|||
/* allocate static storage for *loc */
|
||||
STATIC_VAR(locdata) = calloc (1, sizeof(Local_Data_t));
|
||||
loc = STATIC_VAR(locdata);
|
||||
if (!loc) {
|
||||
cm_message_send("out of memory in sidiode");
|
||||
cm_cexit(1);
|
||||
}
|
||||
|
||||
goff = 1./PARAM(roff);
|
||||
gon = 1./PARAM(ron);
|
||||
|
|
|
|||
|
|
@ -191,6 +191,10 @@ void cm_zener(ARGS) /* structure holding parms,
|
|||
/* Allocate storage for frequencies */
|
||||
STATIC_VAR(previous_voltage) = (double *) malloc(sizeof(double));
|
||||
previous_voltage = (double *) STATIC_VAR(previous_voltage);
|
||||
if (!previous_voltage) {
|
||||
cm_message_send("out of memory in zener");
|
||||
cm_cexit(1);
|
||||
}
|
||||
|
||||
/* Set previous_voltage value to zero... */
|
||||
*previous_voltage = 0.0;
|
||||
|
|
|
|||
|
|
@ -20,13 +20,21 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "ngspice/cmproto.h"
|
||||
#include "tline_common.h"
|
||||
|
||||
#define CHECK_ALLOC(p) { \
|
||||
if (!p) { \
|
||||
cm_message_send("out of memory in tline_common"); \
|
||||
cm_cexit(1); \
|
||||
} \
|
||||
}
|
||||
|
||||
void append_state(tline_state_t **first, double time, double V1, double V2,
|
||||
double I1, double I2, double tmax)
|
||||
{
|
||||
tline_state_t *pp = (tline_state_t *) malloc(sizeof(tline_state_t));
|
||||
CHECK_ALLOC(pp);
|
||||
|
||||
pp->next = NULL;
|
||||
pp->time = time;
|
||||
|
|
@ -106,6 +114,7 @@ void delete_tline_states(tline_state_t **first)
|
|||
void append_cpline_state(cpline_state_t **first, double time, double *Vp, double *Ip, double tmax)
|
||||
{
|
||||
cpline_state_t *pp = (cpline_state_t *) malloc(sizeof(cpline_state_t));
|
||||
CHECK_ALLOC(pp);
|
||||
|
||||
pp->next = NULL;
|
||||
pp->time = time;
|
||||
|
|
|
|||
Loading…
Reference in New Issue