[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnugo-devel] patch: malloc(0) and array bound violation
From: |
Teun Burgers |
Subject: |
[gnugo-devel] patch: malloc(0) and array bound violation |
Date: |
Mon, 21 Jun 2004 20:48:03 +0200 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) |
The problem with malloc(0) returning 0, leading to assertion failures
has not
been fixed to date. For a message on this subject see e.g.
http://lists.gnu.org/archive/html/gnugo-devel/2004-02/msg00037.html
One part of the attached patch (for owl.c) is an update for this problem
for 3.5.8.
The second part is the (temporary) addition of an assertion in optics.c.
There
is an array bound violation here detect by compiling with array bound
checking enabled.
The assertion is triggered in owl.tst for test 3 when running gnugo
--mode gtp < owl.tst.
Teun
diff -u tmp/gnugo-3.5.8/engine/optics.c ./gnugo-3.5.8/engine/optics.c
--- tmp/gnugo-3.5.8/engine/optics.c 2004-06-05 18:27:17.000000000 +0200
+++ ./gnugo-3.5.8/engine/optics.c 2004-06-21 14:09:16.000000000 +0200
@@ -1204,8 +1204,10 @@
vital = black_vital_points;
for (k = 0; k < best_vp->num_defenses && k < MAX_EYE_ATTACKS; k++)
vital[pos].defense_points[k] = best_vp->defenses[k];
- for (k = 0; k < best_vp->num_attacks; k++)
+ for (k = 0; k < best_vp->num_attacks; k++) {
+ ASSERT1(k < MAX_EYE_ATTACKS, pos);
vital[pos].attack_points[k] = best_vp->attacks[k];
+ }
}
return 1;
diff -u tmp/gnugo-3.5.8/engine/owl.c ./gnugo-3.5.8/engine/owl.c
--- tmp/gnugo-3.5.8/engine/owl.c 2004-06-05 18:27:17.000000000 +0200
+++ ./gnugo-3.5.8/engine/owl.c 2004-06-21 14:38:23.000000000 +0200
@@ -3545,8 +3545,8 @@
count_variations = save_count_variations;
}
- free(list->pattern_list);
- free(list->pattern_heap);
+ free(list->pattern_list); list->pattern_list = NULL;
+ free(list->pattern_heap); list->pattern_heap = NULL;
}
list->counter = -1;
}
@@ -3779,7 +3779,14 @@
* heap elements first.
*/
list->pattern_heap = malloc(list->counter * sizeof(*(list->pattern_heap)));
- gg_assert(list->pattern_heap != NULL);
+ if (list->counter > 0) {
+ list->pattern_heap = malloc(list->counter
+ * sizeof(struct matched_pattern_data*));
+ gg_assert(list->pattern_heap != NULL);
+ } else {
+ /* free() has defined behaviour for NULL pointer */
+ list->pattern_heap = NULL;
+ }
for (pos = BOARDMIN; pos < BOARDMAX; pos++)
list->first_pattern_index[pos] = -1;
- [gnugo-devel] patch: malloc(0) and array bound violation,
Teun Burgers <=