MatthiasH
05-25-2007, 08:57 AM
First of all, I implemented all known bugs in svdcmp.cpp, which are posted in the official bug reports.
I got some strange heap-block corruptions using svdcmp. I tracked it down to this code sniplet in svdcmp.cpp:
94: flag=true;
95: for (l=k;l>=0;l--) {
96: nm=l-1;
97: if (fabs(rv1[l])+anorm == anorm) {
98: flag=false;
99: break;
100: }
101: if (fabs(w[nm])+anorm == anorm) break;
102: }
If for any reason check in line 97 does not break when l==0, then array 'w' and 'a' later on get corrupted, because nm is -1.
I suggest the following line:
97: if (fabs(rv1[l])+anorm == anorm || nm<0) {
This avoids memory corruption. The function will possibly not converge at this point, but that is better then corrupting the heap.
Is this a known issue?
Greetings from Germany
Matthias Heinrichs
I got some strange heap-block corruptions using svdcmp. I tracked it down to this code sniplet in svdcmp.cpp:
94: flag=true;
95: for (l=k;l>=0;l--) {
96: nm=l-1;
97: if (fabs(rv1[l])+anorm == anorm) {
98: flag=false;
99: break;
100: }
101: if (fabs(w[nm])+anorm == anorm) break;
102: }
If for any reason check in line 97 does not break when l==0, then array 'w' and 'a' later on get corrupted, because nm is -1.
I suggest the following line:
97: if (fabs(rv1[l])+anorm == anorm || nm<0) {
This avoids memory corruption. The function will possibly not converge at this point, but that is better then corrupting the heap.
Is this a known issue?
Greetings from Germany
Matthias Heinrichs