TangLaoya / polypartition

Automatically exported from code.google.com/p/polypartition
0 stars 0 forks source link

possible flaw in :Triangulate_EC; possible use of uninitialized variable in Triangulate_OPT #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
gcc 4.5.1 reported possible use of uninitialized variables.  It looks like 
there might be some problems:

line 414:

    if(vertices[j].angle > ear->angle) {
        ear = &(vertices[j]);
    }

The value of 'ear' is set, but earfound is not set.  So subsequently, this code 
will be executed:

        if(!earfound) {
            delete [] vertices;
            return 0;
        }

Suggest dropping 'earfound', set 'ear=0' initially, and test for 'ear' not null 
instead of "if(!earfound).

line 579:  potential use of uninitialized variable 'minweight'  Suggest 
initializing to -DBL_MAX.

Original issue reported on code.google.com by gbburkha...@gmail.com on 19 Oct 2012 at 4:10

GoogleCodeExporter commented 9 years ago
Hi, in both of these cases it is impossible to reach the use of uninitialized 
variables.

In the first case, the code on line 414 will never be reached unless earfound 
has been set to true previously, i.e.

earfound = false;
...
if(!earfound) {
   earfound = true;
   ...
} else {
  if(vertices[j].angle > ear->angle) {
    ear = &(vertices[j]);                           
  }
}

In the second case, the variable minweight will never be used if the variable 
bestvertex has value -1.

However, I agree that the code should be modified to avoid false alerts from 
the compiler.

Original comment by ivan.fra...@gmail.com on 20 Oct 2012 at 5:29

GoogleCodeExporter commented 9 years ago
Agreed.

Sorry, for "minweight", I suggest an initial value of "DBL_MAX", not a negative 
value.  But as you point out, it doesn't matter.

Original comment by gbburkha...@gmail.com on 20 Oct 2012 at 12:27

GoogleCodeExporter commented 9 years ago

Original comment by ivan.fra...@gmail.com on 20 Oct 2012 at 6:39

GoogleCodeExporter commented 9 years ago
Hi Ivan Fratric,

Thanks for your excellent code.

For the following case, the result seems to be wrong. Could you please help me 
to take a look at it?

Thanks,
Tang Laoya

data:
2
4
1
 -1.191966510797976E-003  0.202231151541577     
  8.150796829630741E-003  0.186049010752862     
  2.980143192424173E-002  0.198549010752862     
  2.045866858381302E-002  0.214731151541577 
8
0      
  3.525591640424161E-002  0.213001949189431     
  4.514750408646251E-002  0.211126769678226     
  4.301140661905761E-002  0.181202914852858     
 -1.683630303167994E-002  0.185475109787668     
 -1.470020556427498E-002  0.215398964613036     
 -4.642556696250064E-003  0.215850079145971     
  1.537278144042436E-002  0.215352008559904     
  2.045866858381302E-002  0.214731151541577     

Original comment by tanglaoy...@gmail.com on 10 Nov 2012 at 6:54

GoogleCodeExporter commented 9 years ago
Uninitialized variable issues were fixed a while ago.

Original comment by ivan.fra...@gmail.com on 14 Sep 2014 at 10:53