[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [gnugo-devel] 3.3.12: array bound violation in surround.c
From: |
Gunnar Farneback |
Subject: |
Re: [gnugo-devel] 3.3.12: array bound violation in surround.c |
Date: |
Fri, 22 Nov 2002 18:57:00 +0100 |
User-agent: |
EMH/1.14.1 SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.3 Emacs/20.7 (sparc-sun-solaris2.7) (with unibyte mode) |
Teun wrote:
> Array bounds checking revealed an array bound violation in surround.c
> line 265
> It is fixed by this patch
>
> - enlarge mn array in surround.c to avoid array bound violation.
Unfortunately the patch trades a (mostly) harmless array bound
violation for a definitive memory corruption on line 382.
The patch below should be safer.
/Gunnar
Index: engine/surround.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/surround.c,v
retrieving revision 1.3
diff -u -r1.3 surround.c
--- engine/surround.c 18 Nov 2002 06:03:52 -0000 1.3
+++ engine/surround.c 22 Nov 2002 17:49:12 -0000
@@ -261,10 +261,10 @@
/* mark the expanded region */
for (dpos = BOARDMIN; dpos < BOARDMAX; dpos++)
- if (ON_BOARD(dpos) && !mn[dpos] &&
- ((mn[NORTH(dpos)]==1) || (mn[SOUTH(dpos)]==1)
- || (mn[EAST(dpos)]==1) || (mn[WEST(dpos)]==1)))
- mn[dpos] = 2;
+ if (ON_BOARD(dpos) && mn[dpos] == 1)
+ for (k = 0; k < 4; k++)
+ if (ON_BOARD(dpos + delta[k]) && !mn[dpos + delta[k]])
+ mn[dpos + delta[k]] = 2;
/* Mark allied dragons that intersect the (unexpanded) hull.
* These must all lie entirely within the hull for the