CppCheck misses a template function resize that sets data to non NULL.
//this method allocates a new data structure with a given sizetemplate<classFLOAT>voidmatrix<FLOAT>::resize(TSIZEx,TSIZEy){.........if((data=(FLOAT**)calloc(y,sizeof(FLOAT*)))==NULL)//pointers to rows{size2D=size1D=0;//allocation errorRaiseError(MatrixId|No_Memory,this);return;}//memset(data,0,y*sizeof(FLOAT *)) is not needed, calloc clears memory;size2D=y;size1D=x;........return;}
It is strange, because a same situation occurs on line 35 and no "problem" is reported here.
Thanks!
A friend created this ticket: https://trac.cppcheck.net/ticket/14252
We should fix Cppcheck. But you can workaround these false positives if you make your code consistent.
To avoid the false positive you can explicitly specify or drop specification of the template parameter for both declaration and definition. It should not missmatch. Either use matrix<FLOAT> or just matrix in both declaration and definition.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have noted false positive:
** "Condition data==NULL is always true"**
CppCheck misses a template function resize that sets data to non NULL.
It is strange, because a same situation occurs on line 35 and no "problem" is reported here.
Last edit: Jaroslav Fojtik 2025-11-02
Thanks!
A friend created this ticket: https://trac.cppcheck.net/ticket/14252
We should fix Cppcheck. But you can workaround these false positives if you make your code consistent.