| View previous topic :: View next topic |
| Author |
Message |
Jens Bęk Nielsen
Joined: 07 Jul 2011 Posts: 203 Location: Denmark
|
Post subject: Finding errors where indexes goes beyond their boudaries Posted: Sun May 06, 2012 6:34 pm |
|
|
My compiler DevCpp shows there is "An access Violation (Segmentation Fault)" in my chessprogram Dabbaba.
But it is caused by some wrong input - something has been corrupted earlier in the calculations.
I have made a little test to see if DevCpp can detect such things like this:
char testIdx;
char test50a[50];
char test50b[50];
testIdx=75; // outside the array
// ok to read from outside the array?
test50a[25]=test50a[testIdx];
// ok to write outside the array?
test50a[testIdx]=test50a[25];
But DevCpp does not complain about this - everything happens within the program.
And I think this is the way how some of my data is corrupted.
I have tried CppCheck - and it can spot the errors in my little test.
But in a complex program the index is not set to a wrong value right before it is used.
I wonder if there exists an compiler option, that makes it generate code so the program always checks the index boundaries?
Or is there only the hard way to find the error.... |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|