Use calloc instead of malloc with init loop.

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@8493 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Steven Franke 2018-02-11 18:33:16 +00:00
parent 0eb941e082
commit 4f96fbd1ca

View File

@ -73,8 +73,7 @@ unsigned long readc2file(char *ptr_to_infile, float *idat, float *qdat,
char *c2file[15]; char *c2file[15];
FILE* fp; FILE* fp;
buffer=malloc(sizeof(float)*2*65536); buffer=calloc(2*65536,sizeof(float));
for (i=0; i<2*65536; i++) buffer[i]=0.0;
fp = fopen(ptr_to_infile,"rb"); fp = fopen(ptr_to_infile,"rb");
if (fp == NULL) { if (fp == NULL) {
@ -133,7 +132,7 @@ unsigned long readwavfile(char *ptr_to_infile, int ntrmin, float *idat, float *q
FILE *fp; FILE *fp;
short int *buf2; short int *buf2;
buf2 = malloc(npoints*sizeof(short int)); buf2 = calloc(npoints,sizeof(short int));
fp = fopen(ptr_to_infile,"rb"); fp = fopen(ptr_to_infile,"rb");
if (fp == NULL) { if (fp == NULL) {
@ -541,21 +540,12 @@ void subtract_signal2(float *id, float *qd, long np,
float *refi, *refq, *ci, *cq, *cfi, *cfq; float *refi, *refq, *ci, *cq, *cfi, *cfq;
refi=malloc(sizeof(float)*nc2); refi=calloc(nc2,sizeof(float)*nc2);
refq=malloc(sizeof(float)*nc2); refq=calloc(nc2,sizeof(float)*nc2);
ci=malloc(sizeof(float)*nc2); ci=calloc(nc2,sizeof(float)*nc2);
cq=malloc(sizeof(float)*nc2); cq=calloc(nc2,sizeof(float)*nc2);
cfi=malloc(sizeof(float)*nc2); cfi=calloc(nc2,sizeof(float)*nc2);
cfq=malloc(sizeof(float)*nc2); cfq=calloc(nc2,sizeof(float)*nc2);
for (i=0; i<nc2; i++) {
refi[i]=0.0;
refq[i]=0.0;
ci[i]=0.0;
cq[i]=0.0;
cfi[i]=0.0;
cfq[i]=0.0;
}
twopidt=2.0*pi*dt; twopidt=2.0*pi*dt;
@ -658,8 +648,7 @@ unsigned long writec2file(char *c2filename, int trmin, double freq
{ {
int i; int i;
float *buffer; float *buffer;
buffer=malloc(sizeof(float)*2*45000); buffer=calloc(2*45000,sizeof(float));
for (i=0; i<2*45000; i++) buffer[i]=0.0;
FILE *fp; FILE *fp;
@ -753,17 +742,13 @@ int main(int argc, char *argv[])
struct result decodes[50]; struct result decodes[50];
char *hashtab; char *hashtab;
hashtab=malloc(sizeof(char)*32768*13); hashtab=calloc(32768*13,sizeof(char));
memset(hashtab,0,sizeof(char)*32768*13);
int nh; int nh;
symbols=malloc(sizeof(char)*nbits*2); symbols=calloc(nbits*2,sizeof(char));
decdata = malloc(sizeof(char)*11); decdata=calloc(11,sizeof(char));
memset(decdata,0,sizeof(char)*11); channel_symbols=calloc(nbits*2,sizeof(char));
channel_symbols = malloc(sizeof(char)*nbits*2); callsign=calloc(13,sizeof(char));
memset(channel_symbols,0,sizeof(char)*nbits*2); call_loc_pow=calloc(23,sizeof(char));
callsign=malloc(sizeof(char)*13);
call_loc_pow=malloc(sizeof(char)*23);
float allfreqs[100]; float allfreqs[100];
char allcalls[100][13]; char allcalls[100][13];
for (i=0; i<100; i++) allfreqs[i]=0.0; for (i=0; i<100; i++) allfreqs[i]=0.0;
@ -788,12 +773,8 @@ int main(int argc, char *argv[])
int mettab[2][256]; int mettab[2][256];
idat=malloc(sizeof(float)*maxpts); idat=calloc(maxpts,sizeof(float));
qdat=malloc(sizeof(float)*maxpts); qdat=calloc(maxpts,sizeof(float));
for (i=0; i<maxpts; i++) {
idat[i]=0.0;
qdat[i]=0.0;
}
while ( (c = getopt(argc, argv, "a:BcC:de:f:HJmqstwvz:")) !=-1 ) { while ( (c = getopt(argc, argv, "a:BcC:de:f:HJmqstwvz:")) !=-1 ) {
switch (c) { switch (c) {
@ -852,7 +833,7 @@ int main(int argc, char *argv[])
} }
if( stackdecoder ) { if( stackdecoder ) {
stack=malloc(stacksize*sizeof(struct snode)); stack=calloc(sizeof(struct snode),stacksize);
} }
if( optind+1 > argc) { if( optind+1 > argc) {