diff --git a/openair1/SIMULATION/TOOLS/random_channel.c b/openair1/SIMULATION/TOOLS/random_channel.c index 9e9d8afd26..fad949ce93 100644 --- a/openair1/SIMULATION/TOOLS/random_channel.c +++ b/openair1/SIMULATION/TOOLS/random_channel.c @@ -110,7 +110,7 @@ void fill_channel_desc(channel_desc_t *chan_desc, LOG_D(OCM,"[CHANNEL] Doing delays ...\n"); if (delays==NULL) { - chan_desc->delays = (double *) malloc(nb_taps*sizeof(double)); + chan_desc->delays = calloc(nb_taps, sizeof(double)); chan_desc->free_flags=chan_desc->free_flags|CHANMODEL_FREE_DELAY ; delta_tau = Td/nb_taps; @@ -131,22 +131,22 @@ void fill_channel_desc(channel_desc_t *chan_desc, chan_desc->first_run = 1; chan_desc->ip = 0.0; chan_desc->max_Doppler = max_Doppler; - chan_desc->ch = (struct complexd **) malloc(nb_tx*nb_rx*sizeof(struct complexd *)); - chan_desc->chF = (struct complexd **) malloc(nb_tx*nb_rx*sizeof(struct complexd *)); - chan_desc->a = (struct complexd **) malloc(nb_taps*sizeof(struct complexd *)); + chan_desc->ch = calloc(nb_tx*nb_rx, sizeof(struct complexd *)); + chan_desc->chF = calloc(nb_tx*nb_rx, sizeof(struct complexd *)); + chan_desc->a = calloc(nb_taps, sizeof(struct complexd *)); LOG_D(OCM,"[CHANNEL] Filling ch \n"); for (i = 0; ich[i] = (struct complexd *) malloc(channel_length * sizeof(struct complexd)); + chan_desc->ch[i] = calloc(channel_length, sizeof(struct complexd)); for (i = 0; ichF[i] = (struct complexd *) malloc(275 * 12 * sizeof(struct complexd)); // allocate for up to 275 RBs, 12 symbols per RB + chan_desc->chF[i] = calloc(275 * 12, sizeof(struct complexd)); // allocate for up to 275 RBs, 12 symbols per RB LOG_D(OCM,"[CHANNEL] Filling a (nb_taps %d)\n",nb_taps); for (i = 0; ia[i],nb_tx*nb_rx * sizeof(struct complexd)); - chan_desc->a[i] = (struct complexd *) malloc(nb_tx*nb_rx * sizeof(struct complexd)); + chan_desc->a[i] = calloc(nb_tx*nb_rx, sizeof(struct complexd)); } LOG_D(OCM,"[CHANNEL] Doing R_sqrt ...\n"); @@ -637,7 +637,7 @@ channel_desc_t *new_channel_desc_scm(uint8_t nb_tx, chan_desc->Td = 4.625; chan_desc->channel_length = (int) (2*chan_desc->sampling_rate*chan_desc->Td + 1 + 2/(M_PI*M_PI)*log(4*M_PI*chan_desc->sampling_rate*chan_desc->Td)); sum_amps = 0; - chan_desc->amps = (double *) malloc(chan_desc->nb_taps*sizeof(double)); + chan_desc->amps = calloc(chan_desc->nb_taps, sizeof(double)); chan_desc->free_flags=chan_desc->free_flags|CHANMODEL_FREE_AMPS ; for (i = 0; inb_taps; i++) { @@ -657,15 +657,15 @@ channel_desc_t *new_channel_desc_scm(uint8_t nb_tx, chan_desc->a = (struct complexd **) malloc(chan_desc->nb_taps*sizeof(struct complexd *)); for (i = 0; ich[i] = (struct complexd *) malloc(chan_desc->channel_length * sizeof(struct complexd)); + chan_desc->ch[i] = calloc(chan_desc->channel_length, sizeof(struct complexd)); for (i = 0; ichF[i] = (struct complexd *) malloc(1200 * sizeof(struct complexd)); + chan_desc->chF[i] = calloc(1200, sizeof(struct complexd)); for (i = 0; inb_taps; i++) - chan_desc->a[i] = (struct complexd *) malloc(nb_tx*nb_rx * sizeof(struct complexd)); + chan_desc->a[i] = calloc(nb_tx*nb_rx, sizeof(struct complexd)); - chan_desc->R_sqrt = (struct complexd **) malloc(6*sizeof(struct complexd **)); + chan_desc->R_sqrt = calloc(6, sizeof(struct complexd **)); if (nb_tx==2 && nb_rx==2) { for (i = 0; i<6; i++) @@ -680,7 +680,7 @@ channel_desc_t *new_channel_desc_scm(uint8_t nb_tx, chan_desc->free_flags=chan_desc->free_flags|CHANMODEL_FREE_RSQRT_6 ; for (i = 0; i<6; i++) { - chan_desc->R_sqrt[i] = (struct complexd *) malloc(nb_tx*nb_rx*nb_tx*nb_rx * sizeof(struct complexd)); + chan_desc->R_sqrt[i] = calloc(nb_tx*nb_rx*nb_tx*nb_rx, sizeof(struct complexd)); for (j = 0; jR_sqrt[i][j].r = 1.0;