gnugo-devel
[Top][All Lists]
Advanced

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

[gnugo-devel] bugfix for showchar


From: Teun Burgers
Subject: [gnugo-devel] bugfix for showchar
Date: Thu, 15 Nov 2001 23:02:31 +0100

Looking at the gtp bug reported by Anthony, I found
that showchar can lead to an array bound violation.
d->origin=0 in this case.

This one is fixed by the appended patch.

Teun

-- 
Drs A.R. Burgers        Energy research Centre of the Netherlands
Phone: +31-224-564959   P.O. Box 1
Fax  : +31-224-568214   NL-1755 ZG Petten
email: address@hidden   The Netherlands
--- showbord.c  Thu Oct  4 20:38:53 2001
+++ showbord.c.new      Thu Nov 15 14:05:21 2001
@@ -255,8 +255,11 @@
 static void 
 showchar(int i, int j, int empty, int xo)
 {
-  struct dragon_data *d = &(dragon[POS(i, j)]);  /* dragon data at i,j */
-  int x = BOARD(i, j);
+  struct dragon_data *d;  /* dragon data at i,j */
+  int x;
+  ASSERT_ON_BOARD2(i, j);
+  x = BOARD(i, j);
+  d = &(dragon[POS(i, j)]);
 
   if (x == EMPTY) {
     if (xo != 2)
@@ -292,13 +295,17 @@
     }
   }
   else {
-    /* Figure out ascii character for this dragon. This is the
-     * dragon number allocated to the origin of this worm. */
-    int w = dragon_num[I(d->origin)][J(d->origin)];
+    int w;
 
-    if (xo == 0)
+    if (xo == 0 || ! ON_BOARD1(d->origin)) {
       fprintf(stderr, " %c", BOARD(i, j) == BLACK ? 'X' : 'O');
+      return;
+    }
+
+    /* Figure out ascii character for this dragon. This is the
+     * dragon number allocated to the origin of this worm. */
 
+    w = dragon_num[I(d->origin)][J(d->origin)];
     if (!w) {
       /* Not yet allocated - allocate next one. */
       /* Count upwards for black, downwards for white to reduce confusion. */


reply via email to

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