I'm trying using the code analysis function of Visual Studio 2012. I just have run them over my existing project and found some buffer overrun warnings(C6385/C6386) on the part which contains my own implementation of Knuth's subtractive PRNG(aka RAN3). However, I can't understand why this happens because it looks fine(I can see no out-of-bound reads/writes). So I made a short equivalent(below) of that part but still got the same warnings and can't figure out the cause of them.
int main() {
unsigned int k = 1U, seed = 12345U, randomNumbers[55];
randomNumbers[54] = seed;
for(unsigned int i = 1U; i <= 54U; ++i) {
unsigned int ii = ((21U * i) % 55U) - 1U;
randomNumbers[ii] = k;
k = seed - k;
seed = randomNumbers[ii];
}
return 0;
}
With the code above, I got a C6386 warning on line 7 and a C6385 on line 9. What wrong with this code? Am I missing something?