gnugo-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gnugo-devel] arraybound violation in 3.3.16


From: bump
Subject: Re: [gnugo-devel] arraybound violation in 3.3.16
Date: Fri, 31 Jan 2003 07:34:01 -0800

Inge wrote:

> What happens if k < 8?  Looks to me like pos1 is undefined in that
> case and the test ON_BOARD(pos1) can give any random result.

Since the board is convex and both pos2 and pos are on
the board, and pos1 is half way between them, one's first
impression is that if pos and pos2 are on the board so is
pos1. But I guess that if pos is on the left or right
edge, pos2 could be on the other side of the board.

So Inge is right and the function could be written something like:

   for (k = 0; k < 12; k++) {
      int pos1, pos2;
      if (k < 8) {
        pos2 = pos + delta[k];
      } else {
        pos1 = pos + delta[k - 8];
        pos2 = pos + 2 * delta[k - 8];
      }
      
      if (ON_BOARD(pos2)
        && (k < 8 || ON_BOARD(pos1))
        && worm[pos2].color == color
        && dragon[pos2].status != DEAD
        && !disconnect(pos, pos2, NULL)) {
           result = 1;
           break;
      }
    }

Dan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]