From: Tom Hughes Date: Thu, 28 Oct 2004 08:09:05 +0000 (+0000) Subject: Fixed get_height to ensure that SK_MAXHEIGHT-1 is the maximum level we X-Git-Tag: svn/VALGRIND_3_0_0~1435 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8e98a4127a18f37dfd2190bf96483e4dc9745462;p=thirdparty%2Fvalgrind.git Fixed get_height to ensure that SK_MAXHEIGHT-1 is the maximum level we will allocate for a skip list entry as many routines use arrays of size SK_MAXHEIGHT to hold a set of level pointers which means that a level of SK_MAXHEIGHT is not valid due to C arrays being zero based. This led to a number of subtle and hard to locate problems caused by stack based arrays being overflowed by one entry when a node was allocated with the maximum level. As each node only has a one in two million or so chance of getting a level of SK_MAXHEIGHT this didn't actually happen all that often. BUG: 91028 git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2862 --- diff --git a/coregrind/vg_skiplist.c b/coregrind/vg_skiplist.c index a02fb65d0a..1ff3fc319d 100644 --- a/coregrind/vg_skiplist.c +++ b/coregrind/vg_skiplist.c @@ -112,7 +112,7 @@ static inline Int get_height(void) { UInt ret = 0; - while((ret < SK_MAXHEIGHT) && (random() & 1)) + while((ret < SK_MAXHEIGHT - 1) && (random() & 1)) ret++; return ret;