[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [gnugo-devel] arend_3_17.1 crashes
From: |
Arend Bayer |
Subject: |
Re: [gnugo-devel] arend_3_17.1 crashes |
Date: |
Wed, 19 Feb 2003 13:59:30 +0100 (CET) |
> If I compile reading.c without optimization, the crash in
> reading:10 occurs at line 2207 of reading.c. This is the line:
Thanky you, that was a typo just in the line above it, leading to an
array bound violation.
About the warnings: In this case, there is a much better way to silence
them, namely converting the if (pass == ...) chains in attack2/3/4 into
a switch statement, that contains an abort() in the "default:" case.
Then compilers should understand that sgf_message gets initialized in
all code paths.
Arend
diff -u engine/reading.c engine/reading.c
--- engine/reading.c 15 Feb 2003 23:10:54 -0000
+++ engine/reading.c 19 Feb 2003 12:58:06 -0000
@@ -2203,7 +2203,7 @@
if (ss_liberties <= 5) {
for (k = 0; k < ss_liberties; k++) {
int apos = ss_libs[k];
- int alibs[k];
+ int alibs[2];
int alib = accuratelib(apos, other, 2, alibs);
if (liberty_of_string(apos, str))
@@ -3137,7 +3137,8 @@
for (pass = 0; pass < 4; pass++) {
- if (pass == 0) {
+ switch (pass) {
+ case 0:
/* The attack may fail if a boundary string is in atari and cannot
* be defended. First we must try defending such a string.
*
@@ -3231,23 +3232,23 @@
propose_edge_moves(str, libs, liberties, &moves, other);
sgf_message = "attack2-A";
- }
-
- if (pass == 1) {
+ break;
+
+ case 1:
if (stackp <= backfill_depth) {
special_attack2_moves(str, libs, &moves);
special_attack3_moves(str, libs, &moves);
special_attack4_moves(str, libs, &moves);
- sgf_message = "attack2-B";
}
- }
+ sgf_message = "attack2-B";
+ break;
- if (pass == 2) {
+ case 2:
find_cap_moves(str, &moves);
sgf_message = "attack2-C";
- }
+ break;
- if (pass == 3) {
+ case 3:
/* If it is not possible to make a direct atari, we try filling
* a liberty of the superstring.
*/
@@ -3258,10 +3259,13 @@
if (stackp <= backfill2_depth)
liberty_cap = 3;
superstring_moves(str, &moves, liberty_cap, 1);
- sgf_message = "attack2-D";
}
- }
+ sgf_message = "attack2-D";
+ break;
+ default:
+ abort();
+ } /* switch (pass) */
order_moves(str, &moves, other, read_function_name,
saved_num_moves, NO_MOVE);
@@ -3356,7 +3360,8 @@
for (pass = 0; pass < 4; pass++) {
- if (pass == 0) {
+ switch (pass) {
+ case 0:
adj = chainlinks2(str, adjs, 1);
for (r = 0; r < adj; r++) {
int hpos;
@@ -3409,9 +3414,9 @@
/* Pick up some edge moves. */
propose_edge_moves(str, libs, liberties, &moves, other);
sgf_message = "attack3-A";
- }
+ break;
- if (pass == 1) {
+ case 1:
/* The simple ataris didn't work. Try something more fancy. */
if (stackp <= backfill_depth) {
find_cap_moves(str, &moves);
@@ -3421,9 +3426,9 @@
draw_back_moves(str, &moves);
}
sgf_message = "attack3-B";
- }
+ break;
- if (pass == 2) {
+ case 2:
/* Try to defend chain links with two liberties. */
if (stackp <= backfill2_depth) {
adj = chainlinks2(str, adjs, 2);
@@ -3440,15 +3445,19 @@
}
}
sgf_message = "attack3-C";
- }
+ break;
- if (pass == 3) {
+ case 3:
/* If nothing else works, we try filling a liberty of the
* super_string.
*/
if (level >= 10 && stackp <= backfill2_depth)
superstring_moves(str, &moves, 3, 1);
sgf_message = "attack3-D";
+ break;
+
+ default:
+ abort();
}
order_moves(str, &moves, other, read_function_name,
@@ -3535,7 +3544,8 @@
for (pass = 0; pass < 2; pass++) {
- if (pass == 0) {
+ switch (pass) {
+ case 0:
adj = chainlinks2(str, adjs, 1);
for (r = 0; r < adj; r++) {
int hpos;
@@ -3582,13 +3592,17 @@
/* Pick up some edge moves. */
propose_edge_moves(str, libs, liberties, &moves, other);
sgf_message = "attack4-A";
- }
+ break;
- if (pass == 1) {
+ case 1:
if (stackp <= backfill_depth) {
find_cap_moves(str, &moves);
}
sgf_message = "attack4-B";
+ break;
+
+ default:
+ abort();
}
order_moves(str, &moves, other, read_function_name,