vtkMath::LUFactorLinearSystem bugs
vtkMath::LUFactorLinearSystem
has at least 3 bugs that I can see.
- For the signature
vtkTypeBool vtkMath::LUFactorLinearSystem(double** A, int* index, int size)
, there are memory leaks on all the early return paths if the inputsize
is greater than 10. - For the signature
vtkTypeBool vtkMath::LUFactorLinearSystem(double** A, int* index, int size)
in the following code:
if (largest == 0.0 && numWarns++ < VTK_MAX_WARNS)
{
vtkGenericWarningMacro(<< "Unable to factor linear system");
return 0;
}
if numWarns
is greater than 3, then we continue on, editing the A
array when it looks like we should still return. This would then tell the user the operation succeed when it actually failed, and give them garbage output in A
. I believe this was introduced in 0676ee21
The proper reduction of warnings is probably something like
if (largest == 0.0)
{
if (numWarns++ < VTK_MAX_WARNS)
{
vtkGenericWarningMacro(<< "Unable to factor linear system");
}
return 0;
}
Note: the signature vtkTypeBool vtkMath::LUFactorLinearSystem(double** A, int* index, int size, double* tmpSize)
has the exact same issue.
Note: there are multiple places in both functions where this happens, the above link was merely an example of one.
- For the signature
vtkTypeBool vtkMath::LUFactorLinearSystem(double** A, int* index, int size, double* tmpSize)
, it claims to be thread safe, but the usestatic int numWarns;
andnumWarns++
is a race condition. Converting to something likestd::atomic_int
would fix this.