fix several not tested malloc or calloc return value

This commit is contained in:
Laurent THOMAS
2025-09-09 18:04:26 +02:00
committed by Robert Schmidt
parent d372aa1b50
commit 278d2cbca1
13 changed files with 84 additions and 93 deletions
+2 -2
View File
@@ -450,7 +450,7 @@ t_interleaver_codebook *f1f2mat;
short *il_tb;
__attribute__((constructor)) static void init_interleaver(void) {
int totSize=0;
f1f2mat=(t_interleaver_codebook*) malloc(sizeof(*f1f2mat) * sizeof(f1f2) / sizeof(*f1f2));
f1f2mat = malloc_or_fail(sizeof(*f1f2mat) * sizeof(f1f2) / sizeof(*f1f2));
for (int i=0; i < sizeof(f1f2)/sizeof(*f1f2) ; i++) {
f1f2mat[i].nb_bits=f1f2[i].nb_bits;
f1f2mat[i].f1=f1f2[i].f1;
@@ -458,7 +458,7 @@ __attribute__((constructor)) static void init_interleaver(void) {
f1f2mat[i].beg_index=totSize;
totSize+=f1f2mat[i].nb_bits;
}
il_tb=(short*)malloc(sizeof(*il_tb)*totSize);
il_tb = malloc_or_fail(sizeof(*il_tb) * totSize);
int idx=0;
for (int i=0; i < sizeof(f1f2)/sizeof(*f1f2) ; i++)
for (uint64_t j=0; j<f1f2[i].nb_bits; j++)
@@ -30,7 +30,7 @@ const uint8_t **crc24c_generator_matrix(uint16_t payloadSizeBits)
uint8_t temp1[crcPolynomialSize], temp2[crcPolynomialSize];
uint8_t **crc_generator_matrix =
malloc(payloadSizeBits * sizeof(uint8_t *) + payloadSizeBits * crcPolynomialSize * sizeof(uint8_t));
malloc_or_fail(payloadSizeBits * sizeof(uint8_t *) + payloadSizeBits * crcPolynomialSize * sizeof(uint8_t));
if (crc_generator_matrix)
for (int i = 0; i < payloadSizeBits; i++)
crc_generator_matrix[i] = ((uint8_t *)&crc_generator_matrix[payloadSizeBits]) + i * crcPolynomialSize;
+3 -3
View File
@@ -63,9 +63,9 @@ void lte_param_init(PHY_VARS_eNB **eNBp,
PHY_VARS_UE *UE;
RU_t *ru;
printf("Start lte_param_init\n");
*eNBp = malloc(sizeof(PHY_VARS_eNB));
*UEp = malloc(sizeof(PHY_VARS_UE));
*rup = malloc(sizeof(RU_t));
*eNBp = malloc_or_fail(sizeof(PHY_VARS_eNB));
*UEp = malloc_or_fail(sizeof(PHY_VARS_UE));
*rup = malloc_or_fail(sizeof(RU_t));
eNB = *eNBp;
UE = *UEp;
ru = *rup;
@@ -22,7 +22,7 @@ data storage. */
#include <lapacke_utils.h>
#include <lapacke.h>
//#define DEBUG_PREPROC
#include "common/utils/utils.h"
void transpose (int N, float complex *A, float complex *Result)
{
@@ -43,14 +43,14 @@ void transpose (int N, float complex *A, float complex *Result)
int ldb = col_opB;
if (transb == CblasNoTrans) {
B = (float complex*)calloc(ldb*col_opB,sizeof(float complex));
B = calloc_or_fail(ldb * col_opB, sizeof(float complex));
col_B= col_opB;
}
else {
B = (float complex*)calloc(ldb*col_opA, sizeof(float complex));
B = calloc_or_fail(ldb * col_opA, sizeof(float complex));
col_B = col_opA;
}
float complex* C = (float complex*)malloc(ldc*col_opB*sizeof(float complex));
float complex* C = malloc_or_fail(ldc * col_opB * sizeof(float complex));
for (i=0; i<lda*col_B; i+=N+1)
B[i]=1.0+I*0;
@@ -82,14 +82,14 @@ void conjugate_transpose (int N, float complex *A, float complex *Result)
int ldb = col_opB;
if (transb == CblasNoTrans) {
B = (float complex*)calloc(ldb*col_opB,sizeof(float complex));
B = calloc_or_fail(ldb * col_opB, sizeof(float complex));
col_B= col_opB;
}
else {
B = (float complex*)calloc(ldb*col_opA, sizeof(float complex));
B = calloc_or_fail(ldb * col_opA, sizeof(float complex));
col_B = col_opA;
}
float complex* C = (float complex*)malloc(ldc*col_opB*sizeof(float complex));
float complex* C = malloc_or_fail(ldc * col_opB * sizeof(float complex));
for (i=0; i<lda*col_B; i+=N+1)
B[i]=1.0+I*0;
@@ -117,7 +117,7 @@ void H_hermH_plus_sigma2I (int N, int M, float complex *A, float sigma2, float c
int ldc = col_opA;
int i;
float complex* C = (float complex*)calloc(ldc*col_opB, sizeof(float complex));
float complex* C = calloc_or_fail(ldc * col_opB, sizeof(float complex));
for (i=0; i<lda*col_C; i+=N+1)
C[i]=sigma2*(1.0+I*0);
@@ -141,7 +141,7 @@ void H_hermH_plus_sigma2I (int N, int M, float complex *A, float sigma2, float c
int ldc = M;
int i;
float complex* C = (float complex*)calloc(M*M, sizeof(float complex));
float complex* C = calloc_or_fail(M * M, sizeof(float complex));
for (i=0; i<M*M; i+=M+1)
C[i]=1.0+I*0;
@@ -163,7 +163,7 @@ void eigen_vectors_values (int N, float complex *A, float complex *Vectors, floa
int order_A = N;
int lda = N;
int i;
float* Values = (float*)malloc(sizeof(float)*1*N);
float* Values = malloc_or_fail(sizeof(float) * 1 * N);
LAPACKE_cheev(LAPACK_ROW_MAJOR, jobz, uplo, order_A, A, lda, Values);
@@ -183,7 +183,7 @@ void eigen_vectors_values (int N, float complex *A, float complex *Vectors, floa
int nrhs = N;
char transa = 'N';
int* IPIV = malloc(N*N*sizeof(int));
int* IPIV = malloc_or_fail(N * N * sizeof(int));
// Compute LU-factorization
LAPACKE_cgetrf(LAPACK_ROW_MAJOR, n, nrhs, A, lda, IPIV);
@@ -267,8 +267,8 @@ void mutl_matrix_matrix_col_based(float complex* M0, float complex* M1, int rows
void compute_MMSE(float complex* H, int order_H, float sigma2, float complex* W_MMSE)
{
int N = order_H;
float complex* H_hermH_sigmaI = malloc(N*N*sizeof(float complex));
float complex* H_herm = malloc(N*N*sizeof(float complex));
float complex* H_hermH_sigmaI = malloc_or_fail(N * N * sizeof(float complex));
float complex* H_herm = malloc_or_fail(N * N * sizeof(float complex));
H_hermH_plus_sigma2I(N, N, H, sigma2, H_hermH_sigmaI);
@@ -309,18 +309,18 @@ void compute_white_filter(float complex* H_re,
int N = n_tx;
int sigma2=noise_power;
float complex *H0_re = malloc(n_rx*(n_tx>>2)*sizeof(float complex));
float complex *H1_re = malloc(n_rx*(n_tx>>2)*sizeof(float complex));
float complex *R_corr_col_n_0_re = malloc(n_rx*n_tx*sizeof(float complex));
float complex *R_corr_col_n_1_re = malloc(n_rx*n_tx*sizeof(float complex));
float complex *U_0_re = malloc(n_rx*n_tx*sizeof(float complex));
float complex *U_1_re = malloc(n_rx*n_tx*sizeof(float complex));
float complex *U_0_herm_re = malloc(n_rx*n_tx*sizeof(float complex));
float complex *U_1_herm_re = malloc(n_rx*n_tx*sizeof(float complex));
float complex *D_0_re = malloc(n_rx*n_tx*sizeof(float complex));
float complex *D_1_re = malloc(n_rx*n_tx*sizeof(float complex));
float complex *W_Wh_0_re = malloc(n_rx*n_tx*sizeof(float complex));
float complex *W_Wh_1_re = malloc(n_rx*n_tx*sizeof(float complex));
float complex *H0_re = malloc_or_fail(n_rx*(n_tx>>2)*sizeof(float complex));
float complex *H1_re = malloc_or_fail(n_rx*(n_tx>>2)*sizeof(float complex));
float complex *R_corr_col_n_0_re = malloc_or_fail(n_rx*n_tx*sizeof(float complex));
float complex *R_corr_col_n_1_re = malloc_or_fail(n_rx*n_tx*sizeof(float complex));
float complex *U_0_re = malloc_or_fail(n_rx*n_tx*sizeof(float complex));
float complex *U_1_re = malloc_or_fail(n_rx*n_tx*sizeof(float complex));
float complex *U_0_herm_re = malloc_or_fail(n_rx*n_tx*sizeof(float complex));
float complex *U_1_herm_re = malloc_or_fail(n_rx*n_tx*sizeof(float complex));
float complex *D_0_re = malloc_or_fail(n_rx*n_tx*sizeof(float complex));
float complex *D_1_re = malloc_or_fail(n_rx*n_tx*sizeof(float complex));
float complex *W_Wh_0_re = malloc_or_fail(n_rx*n_tx*sizeof(float complex));
float complex *W_Wh_1_re = malloc_or_fail(n_rx*n_tx*sizeof(float complex));
for (aatx=0; aatx<n_tx/2; aatx++){
for (aarx=0; aarx<n_rx; aarx++) {
+3 -3
View File
@@ -67,7 +67,7 @@ static void drawsymbol(FL_OBJECT *obj, int id,
static void commonGraph(OAIgraph_t *graph, int type, FL_Coord x, FL_Coord y, FL_Coord w, FL_Coord h, const char *label, FL_COLOR pointColor) {
if (type==WATERFALL) {
graph->waterFallh=h-15;
graph->waterFallAvg=malloc(sizeof(*graph->waterFallAvg) * graph->waterFallh);
graph->waterFallAvg = malloc_or_fail(sizeof(*graph->waterFallAvg) * graph->waterFallh);
for (int i=0; i< graph->waterFallh; i++)
graph->waterFallAvg[i]=0;
@@ -309,7 +309,7 @@ static void puschIQ (OAIgraph_t *graph, calibData_t *context) {
static OAI_phy_scope_t *createScopeCalibration(calibData_t * context) {
FL_OBJECT *obj;
OAI_phy_scope_t *fdui = calloc(( sizeof *fdui ),1);
OAI_phy_scope_t *fdui = calloc_or_fail((sizeof *fdui), 1);
fdui->context=context;
// Define form
fdui->phy_scope = fl_bgn_form( FL_NO_BOX, 800, 800 );
@@ -380,7 +380,7 @@ static void *scopeThread(void *arg) {
void CalibrationInitScope(void ** samplesRx,openair0_device *rfdevice) {
pthread_t forms_thread;
calibData_t * tmp=(calibData_t *) malloc(sizeof(*tmp));
calibData_t *tmp = (calibData_t *)malloc_or_fail(sizeof(*tmp));
tmp->samplesRx=samplesRx;
tmp->rfdevice=rfdevice;
threadCreate(&forms_thread, scopeThread, (void*) tmp, "scope", -1, OAI_PRIORITY_RT_LOW);
+5 -5
View File
@@ -614,7 +614,7 @@ static void puschThroughtput (OAIgraph_t *graph, scopeData_t *p, int nb_UEs) {
STATICFORXSCOPE OAI_phy_scope_t *create_phy_scope_gnb(void)
{
FL_OBJECT *obj;
OAI_phy_scope_t *fdui = calloc(( sizeof *fdui ),1);
OAI_phy_scope_t *fdui = calloc_or_fail((sizeof *fdui), 1);
// Define form
fdui->phy_scope = fl_bgn_form( FL_NO_BOX, 800, 800 );
fl_set_form_dblbuffer(fdui->phy_scope, 1);
@@ -739,7 +739,7 @@ static void scopeUpdaterGnb(enum PlotTypeGnbIf plotType, int numElt)
STATICFORXSCOPE void gNBinitScope(scopeParms_t *p)
{
AssertFatal(p->gNB->scopeData = calloc(sizeof(scopeData_t), 1), "");
AssertFatal(p->gNB->scopeData = calloc_or_fail(sizeof(scopeData_t), 1), "");
scopeData_t *scope=(scopeData_t *) p->gNB->scopeData;
scope->argc=p->argc;
scope->argv=p->argv;
@@ -998,7 +998,7 @@ static void uePdschThroughput (scopeGraphData_t **data, OAIgraph_t *graph, PHY_
STATICFORXSCOPE OAI_phy_scope_t *create_phy_scope_nrue(int ID)
{
FL_OBJECT *obj;
OAI_phy_scope_t *fdui = calloc(( sizeof *fdui ),1);
OAI_phy_scope_t *fdui = calloc_or_fail((sizeof *fdui), 1);
// Define form
fdui->phy_scope = fl_bgn_form( FL_NO_BOX, 800, 900 );
fl_set_form_dblbuffer(fdui->phy_scope, 1);
@@ -1139,7 +1139,7 @@ static void *nrUEscopeThread(void *arg) {
STATICFORXSCOPE void nrUEinitScope(PHY_VARS_NR_UE *ue)
{
AssertFatal(ue->scopeData = calloc(sizeof(scopeData_t), 1), "");
AssertFatal(ue->scopeData = calloc_or_fail(sizeof(scopeData_t), 1), "");
scopeData_t *scope=(scopeData_t *) ue->scopeData;
scope->copyData = copyData;
#ifndef WEBSRVSCOPE
@@ -1185,7 +1185,7 @@ static void reset_stats_gNB(FL_OBJECT *button,
}
static FD_stats_form *create_form_stats_form(int ID) {
FL_OBJECT *obj;
FD_stats_form *fdui = calloc(( sizeof *fdui ),1);
FD_stats_form *fdui = calloc_or_fail(( sizeof *fdui ),1);
fdui->vdata = fdui->cdata = NULL;
fdui->ldata = 0;
fdui->stats_form = fl_bgn_form( FL_NO_BOX, 1115, 900 );