Closed RobinHankin closed 3 years ago
not 100% sure I am reading the valgrind output correctly but it seems that there are two distinct errors: one from eddington
and one from the partitions
package. The line in question is:
for(i=0 ; x[i] > i && i < nrow; i++)
and I think what is happening is that the second argument x[]>i && i<nrow
is buggy. If i==nrow-1
and x[i]>i
then i
will be incremented. Then control will execute x[]>i && i<nrow
(but with i==nrow
). So it will try to read x[i]
which is x[nrow]
which is out of bounds. We can correct this by swapping the order of the tests so it reads
for(i=0 ; i<nrow && x[i]>i ; i++)
I spoke with Steffan Hooper about it and he suggests rewriting to use a while()
loop instead.
The while()
code would be
int durfee_vector(const int *x, const int nrow)
{
int i=0;
while(i<nrow){
if(x[i] <= i){break;}
i++;
}
return i;
}
automated error message from Brian Ripley: