I get this error with Spin 6.4.8
:
spin: indexing channels[-1] - size is 3
spin: 2.pml:13, Error: indexing array 'channels'
when running a simulation of the following Promela Model:
chan channels[3] = [1] of { pid };
active [3] proctype node () {
short pred = (_pid - 1) % 3;
short succ = (_pid + 1) % 3;
printf("Values(%d): %d, %d\n", _pid, pred, succ);
if
:: pred == -1 -> pred = 2;
:: else -> skip;
fi;
printf("Corrected Values(%d): %d, %d\n", _pid, pred, succ);
{
chan pc = channels[pred];
chan sc = channels[succ];
}
}
As witnessed by the following output trace, I do not access the offending -1
array location as claimed by the error message:
Values(0): -1, 1
Values(2): 1, 0
Values(1): 0, 2
Corrected Values(1): 0, 2
Corrected Values(2): 1, 0
Corrected Values(0): 2, 1
After further analysis, which is not shown here, it also looks like that pc
and sc
are always initialized to the right channel value when I try to access them.
Q: why do I get an error message, and how do I fix that?