문제

In my code, I am using an array xyz of 10 objects. When I am trying to access an element of the array using an unsigned int index like this: xyz[level], I get 'Buffer overrun' warning. Logically, I am pretty sure that level won't exceed 10. How to avoid this warning?

도움이 되었습니까?

해결책

I'm probably teaching my grandmother to suck eggs here, but do remember that "level won't exceed 10" is wrong for an array of size 10:

char a[10];
a[10] = '\0';  // Bug, and "Buffer Overrun" warning.

다른 팁

Are you really sure? I never got this warning until now. So, double check.

Anyway, you can use the

#pragma warning( disable: 6386 )

preprocessor directive. I usually push and pop this to the "pragma stack"

#pragma warning( push )
#pragma warning( disable : 6386 )
// Some code
#pragma warning( pop )

as advised here.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top