Skip to content

Commit

Permalink
Fix compilation warnings to error, mostly use-after-free and maybe un…
Browse files Browse the repository at this point in the history
…initialized.
  • Loading branch information
Silvanosky committed Aug 17, 2023
1 parent 557350d commit bc58e49
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 59 deletions.
3 changes: 3 additions & 0 deletions include/ext_stl/fifo.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ template <class Type> class ElFifo

void incr_capa()
{
if (_capa == 0)
_capa = 1;

Type * NewTab = new Type [2*_capa];
for (INT kk=0; kk<_nb ; kk++)
NewTab[kk] = _tab[(kk+_begin)%_capa];
Expand Down
2 changes: 1 addition & 1 deletion src/TpMMPD/DeformAnalyse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ int DeformAnalyse_main (int argc, char ** argv)

// 3. get the vector PerResidu
ifstream aPR((aDir + aOut1).c_str());
char *aPerR;
char *aPerR{nullptr};
if(aPR)
{
std::string aLine;
Expand Down
2 changes: 1 addition & 1 deletion src/TpMMPD/TiePByMesh/TaskCorrel/cAppliTaskCorrel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void cAppliTaskCorrel::ReadXMLMesurePts(string aGCPMesureXML, vector<cImgForTiep
std::list<cOneMesureAF1I> & aMes = iT1->OneMesureAF1I();
string aNameIm = iT1->NameIm();
cout<<endl<<" + Img : "<<aNameIm<<endl;
cImgForTiepTri* aImg;
cImgForTiepTri* aImg{};
for (uint akIm=0; akIm<mVImgs.size(); akIm++)
{
if (aNameIm == mVImgs[akIm]->Name())
Expand Down
125 changes: 69 additions & 56 deletions src/uti_phgrm/GraphCut/MaxFlow/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,64 +58,77 @@ template <typename captype, typename tcaptype, typename flowtype>
flow = 0;
}

template <typename captype, typename tcaptype, typename flowtype>
void Graph<captype,tcaptype,flowtype>::reallocate_nodes(int num)
{
int node_num_max = (int)(node_max - nodes);
node* nodes_old = nodes;

node_num_max += node_num_max / 2;
if (node_num_max < node_num + num) node_num_max = node_num + num;
nodes = (node*) realloc(nodes_old, node_num_max*sizeof(node));
if (!nodes) { if (error_function) (*error_function)("Not enough memory!"); exit(1); }

node_last = nodes + node_num;
node_max = nodes + node_num_max;

if (nodes != nodes_old)
{
node* i;
arc* a;
for (i=nodes; i<node_last; i++)
{
if (i->next) i->next = (node*) ((char*)i->next + (((char*) nodes) - ((char*) nodes_old)));
}
for (a=arcs; a<arc_last; a++)
{
a->head = (node*) ((char*)a->head + (((char*) nodes) - ((char*) nodes_old)));
}
}
template <typename captype, typename tcaptype, typename flowtype>
void Graph<captype, tcaptype, flowtype>::reallocate_nodes(int num) {
int node_num_max = (int)(node_max - nodes);
size_t nodes_old = (size_t)nodes;

node_num_max += node_num_max / 2;
if (node_num_max < node_num + num) node_num_max = node_num + num;

nodes = (node*)realloc(nodes, node_num_max * sizeof(node));

if (!nodes) {
if (error_function) (*error_function)("Not enough memory!");
exit(1);
}

node_last = nodes + node_num;
node_max = nodes + node_num_max;

if ((size_t)nodes != nodes_old) {
node* i;
arc* a;
for (i = nodes; i < node_last; i++) {
if (i->next)
i->next =
(node*)((size_t)i->next +
(((size_t)nodes) - ((size_t)nodes_old)));
}
for (a = arcs; a < arc_last; a++) {
a->head = (node*)((size_t)a->head +
(((size_t)nodes) - ((size_t)nodes_old)));
}
}
}

template <typename captype, typename tcaptype, typename flowtype>
void Graph<captype,tcaptype,flowtype>::reallocate_arcs()
{
int arc_num_max = (int)(arc_max - arcs);
int arc_num = (int)(arc_last - arcs);
arc* arcs_old = arcs;

arc_num_max += arc_num_max / 2; if (arc_num_max & 1) arc_num_max ++;
arcs = (arc*) realloc(arcs_old, arc_num_max*sizeof(arc));
if (!arcs) { if (error_function) (*error_function)("Not enough memory!"); exit(1); }

arc_last = arcs + arc_num;
arc_max = arcs + arc_num_max;

if (arcs != arcs_old)
{
node* i;
arc* a;
for (i=nodes; i<node_last; i++)
{
if (i->first) i->first = (arc*) ((char*)i->first + (((char*) arcs) - ((char*) arcs_old)));
if (i->parent && i->parent != ORPHAN && i->parent != TERMINAL) i->parent = (arc*) ((char*)i->parent + (((char*) arcs) - ((char*) arcs_old)));
}
for (a=arcs; a<arc_last; a++)
{
if (a->next) a->next = (arc*) ((char*)a->next + (((char*) arcs) - ((char*) arcs_old)));
a->sister = (arc*) ((char*)a->sister + (((char*) arcs) - ((char*) arcs_old)));
}
}
template <typename captype, typename tcaptype, typename flowtype>
void Graph<captype, tcaptype, flowtype>::reallocate_arcs() {
int arc_num_max = (int)(arc_max - arcs);
int arc_num = (int)(arc_last - arcs);
size_t arcs_old = (size_t)arcs;

arc_num_max += arc_num_max / 2;
if (arc_num_max & 1) arc_num_max++;
arcs = (arc*)realloc(arcs, arc_num_max * sizeof(arc));
if (!arcs) {
if (error_function) (*error_function)("Not enough memory!");
exit(1);
}

arc_last = arcs + arc_num;
arc_max = arcs + arc_num_max;

if ((size_t)arcs != arcs_old) {
node* i;
arc* a;
for (i = nodes; i < node_last; i++) {
if (i->first)
i->first = (arc*)((size_t)i->first +
(((size_t)arcs) - ((size_t)arcs_old)));
if (i->parent && i->parent != ORPHAN &&
i->parent != TERMINAL)
i->parent = (arc*)((size_t)i->parent +
(((size_t)arcs) - ((size_t)arcs_old)));
}
for (a = arcs; a < arc_last; a++) {
if (a->next)
a->next = (arc*)((size_t)a->next +
(((size_t)arcs) - ((size_t)arcs_old)));
a->sister = (arc*)((size_t)a->sister +
(((size_t)arcs) - ((size_t)arcs_old)));
}
}
}

#include "instances.inc"
2 changes: 1 addition & 1 deletion src/util/regex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ cElRegex::cElRegex(const std::string & aNameExprIn,int aNbMatchMax,int aCFlag,bo

if (! IsOk())
return;
regmatch_t aMatch;
regmatch_t aMatch{};
mVMatch.reserve(aNbMatchMax);
for (int aK=0; aK<aNbMatchMax ; aK++)
mVMatch.push_back(aMatch);
Expand Down

0 comments on commit bc58e49

Please sign in to comment.