Skip to content

Commit bc58e49

Browse files
committed
Fix compilation warnings to error, mostly use-after-free and maybe uninitialized.
1 parent 557350d commit bc58e49

5 files changed

Lines changed: 75 additions & 59 deletions

File tree

include/ext_stl/fifo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ template <class Type> class ElFifo
197197

198198
void incr_capa()
199199
{
200+
if (_capa == 0)
201+
_capa = 1;
202+
200203
Type * NewTab = new Type [2*_capa];
201204
for (INT kk=0; kk<_nb ; kk++)
202205
NewTab[kk] = _tab[(kk+_begin)%_capa];

src/TpMMPD/DeformAnalyse.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ int DeformAnalyse_main (int argc, char ** argv)
7676

7777
// 3. get the vector PerResidu
7878
ifstream aPR((aDir + aOut1).c_str());
79-
char *aPerR;
79+
char *aPerR{nullptr};
8080
if(aPR)
8181
{
8282
std::string aLine;

src/TpMMPD/TiePByMesh/TaskCorrel/cAppliTaskCorrel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void cAppliTaskCorrel::ReadXMLMesurePts(string aGCPMesureXML, vector<cImgForTiep
116116
std::list<cOneMesureAF1I> & aMes = iT1->OneMesureAF1I();
117117
string aNameIm = iT1->NameIm();
118118
cout<<endl<<" + Img : "<<aNameIm<<endl;
119-
cImgForTiepTri* aImg;
119+
cImgForTiepTri* aImg{};
120120
for (uint akIm=0; akIm<mVImgs.size(); akIm++)
121121
{
122122
if (aNameIm == mVImgs[akIm]->Name())

src/uti_phgrm/GraphCut/MaxFlow/graph.cpp

Lines changed: 69 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -58,64 +58,77 @@ template <typename captype, typename tcaptype, typename flowtype>
5858
flow = 0;
5959
}
6060

61-
template <typename captype, typename tcaptype, typename flowtype>
62-
void Graph<captype,tcaptype,flowtype>::reallocate_nodes(int num)
63-
{
64-
int node_num_max = (int)(node_max - nodes);
65-
node* nodes_old = nodes;
66-
67-
node_num_max += node_num_max / 2;
68-
if (node_num_max < node_num + num) node_num_max = node_num + num;
69-
nodes = (node*) realloc(nodes_old, node_num_max*sizeof(node));
70-
if (!nodes) { if (error_function) (*error_function)("Not enough memory!"); exit(1); }
71-
72-
node_last = nodes + node_num;
73-
node_max = nodes + node_num_max;
74-
75-
if (nodes != nodes_old)
76-
{
77-
node* i;
78-
arc* a;
79-
for (i=nodes; i<node_last; i++)
80-
{
81-
if (i->next) i->next = (node*) ((char*)i->next + (((char*) nodes) - ((char*) nodes_old)));
82-
}
83-
for (a=arcs; a<arc_last; a++)
84-
{
85-
a->head = (node*) ((char*)a->head + (((char*) nodes) - ((char*) nodes_old)));
86-
}
87-
}
61+
template <typename captype, typename tcaptype, typename flowtype>
62+
void Graph<captype, tcaptype, flowtype>::reallocate_nodes(int num) {
63+
int node_num_max = (int)(node_max - nodes);
64+
size_t nodes_old = (size_t)nodes;
65+
66+
node_num_max += node_num_max / 2;
67+
if (node_num_max < node_num + num) node_num_max = node_num + num;
68+
69+
nodes = (node*)realloc(nodes, node_num_max * sizeof(node));
70+
71+
if (!nodes) {
72+
if (error_function) (*error_function)("Not enough memory!");
73+
exit(1);
74+
}
75+
76+
node_last = nodes + node_num;
77+
node_max = nodes + node_num_max;
78+
79+
if ((size_t)nodes != nodes_old) {
80+
node* i;
81+
arc* a;
82+
for (i = nodes; i < node_last; i++) {
83+
if (i->next)
84+
i->next =
85+
(node*)((size_t)i->next +
86+
(((size_t)nodes) - ((size_t)nodes_old)));
87+
}
88+
for (a = arcs; a < arc_last; a++) {
89+
a->head = (node*)((size_t)a->head +
90+
(((size_t)nodes) - ((size_t)nodes_old)));
91+
}
92+
}
8893
}
8994

90-
template <typename captype, typename tcaptype, typename flowtype>
91-
void Graph<captype,tcaptype,flowtype>::reallocate_arcs()
92-
{
93-
int arc_num_max = (int)(arc_max - arcs);
94-
int arc_num = (int)(arc_last - arcs);
95-
arc* arcs_old = arcs;
96-
97-
arc_num_max += arc_num_max / 2; if (arc_num_max & 1) arc_num_max ++;
98-
arcs = (arc*) realloc(arcs_old, arc_num_max*sizeof(arc));
99-
if (!arcs) { if (error_function) (*error_function)("Not enough memory!"); exit(1); }
100-
101-
arc_last = arcs + arc_num;
102-
arc_max = arcs + arc_num_max;
103-
104-
if (arcs != arcs_old)
105-
{
106-
node* i;
107-
arc* a;
108-
for (i=nodes; i<node_last; i++)
109-
{
110-
if (i->first) i->first = (arc*) ((char*)i->first + (((char*) arcs) - ((char*) arcs_old)));
111-
if (i->parent && i->parent != ORPHAN && i->parent != TERMINAL) i->parent = (arc*) ((char*)i->parent + (((char*) arcs) - ((char*) arcs_old)));
112-
}
113-
for (a=arcs; a<arc_last; a++)
114-
{
115-
if (a->next) a->next = (arc*) ((char*)a->next + (((char*) arcs) - ((char*) arcs_old)));
116-
a->sister = (arc*) ((char*)a->sister + (((char*) arcs) - ((char*) arcs_old)));
117-
}
118-
}
95+
template <typename captype, typename tcaptype, typename flowtype>
96+
void Graph<captype, tcaptype, flowtype>::reallocate_arcs() {
97+
int arc_num_max = (int)(arc_max - arcs);
98+
int arc_num = (int)(arc_last - arcs);
99+
size_t arcs_old = (size_t)arcs;
100+
101+
arc_num_max += arc_num_max / 2;
102+
if (arc_num_max & 1) arc_num_max++;
103+
arcs = (arc*)realloc(arcs, arc_num_max * sizeof(arc));
104+
if (!arcs) {
105+
if (error_function) (*error_function)("Not enough memory!");
106+
exit(1);
107+
}
108+
109+
arc_last = arcs + arc_num;
110+
arc_max = arcs + arc_num_max;
111+
112+
if ((size_t)arcs != arcs_old) {
113+
node* i;
114+
arc* a;
115+
for (i = nodes; i < node_last; i++) {
116+
if (i->first)
117+
i->first = (arc*)((size_t)i->first +
118+
(((size_t)arcs) - ((size_t)arcs_old)));
119+
if (i->parent && i->parent != ORPHAN &&
120+
i->parent != TERMINAL)
121+
i->parent = (arc*)((size_t)i->parent +
122+
(((size_t)arcs) - ((size_t)arcs_old)));
123+
}
124+
for (a = arcs; a < arc_last; a++) {
125+
if (a->next)
126+
a->next = (arc*)((size_t)a->next +
127+
(((size_t)arcs) - ((size_t)arcs_old)));
128+
a->sister = (arc*)((size_t)a->sister +
129+
(((size_t)arcs) - ((size_t)arcs_old)));
130+
}
131+
}
119132
}
120133

121134
#include "instances.inc"

src/util/regex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ cElRegex::cElRegex(const std::string & aNameExprIn,int aNbMatchMax,int aCFlag,bo
106106

107107
if (! IsOk())
108108
return;
109-
regmatch_t aMatch;
109+
regmatch_t aMatch{};
110110
mVMatch.reserve(aNbMatchMax);
111111
for (int aK=0; aK<aNbMatchMax ; aK++)
112112
mVMatch.push_back(aMatch);

0 commit comments

Comments
 (0)