Computer Chess Club Archives


Search

Terms

Messages

Subject: Programming question: Array Bounds Checking

Author: Heiko Mikala

Date: 13:18:20 08/22/99


Hi everybody!

For a very long time I had the feeling, that there is a serious bug somewhere in
my chess program, because from time to time it played very silly moves, which I
was unable to explain and even unable to reproduce. My thoughts for a long time
have been, that somewhere in the code I must be writing over array bounds and
overwriting other variables this way.

Now, the latest version of my program sometimes overlooks 3-fold repetitions and
sometimes refuses to resign, which it should do, if for 4 moves in a row it's
score is below a certain, adjustable value. This now is the definite proof for
my thesis, because both of the above mentioned features rely on values in my
move history array, which should always be correct, and the code to detect
3-fold repetition or to resign is as simple as it can be.

Unfortunately, the errors are still not reproducable. If I replay the games by
hand from a position shortly before the error occurred, everything works fine -
the errors only occur during whole games, and maybe even only in the release
version, not in the debug version. More than that, different compilers give
different bugs...

Of course, I could look through my program's source code line by line, trying to
locate the place where the variables are overwritten, but that seems to be
nearly impossible. I did that about one year ago, and I really found two bugs,
but ever since then, I had the feeling that I didn't find all the bugs.

Now, my question is, is there a tool available, which detects when I try to
access arrays with invalid bounds? Or which detects, when other variables get
unintentionally overwritten? I remember the good old Turbo Pascal days (many,
many years ago...). TP had such checks built in - it would tell you, when the
program tried to write over array bounds.

My program is written in C, and I have different compilers available (MSVC 6,
Watcom C++ 10.0a, Symantec C++ 7.0). Does any of these compilers/debuggers have
such an option, which I overlooked?

I heard of a tool called "Bounds Checker" and one other such tool (forgot it's
name), are these tools worth their money? Are comparable freeware tools
available somewhere? I would prefer Windows-based tools, but Linux would do too
(would be the final reason to port the program to Linux again ;-)

What do others do to locate such bugs?


Thank you for your help (and please forgive my bad english),

Heiko.




This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.