shithub: puzzles

Download patch

ref: 9c95ea261980860cf74bc583417981960f91648b
parent: ddbe9abe8aeaadfb79251f89321916071867eb78
author: Simon Tatham <anakin@pobox.com>
date: Tue Nov 10 14:11:03 EST 2009

Add a precautionary pair of initialisations to placate optimisers,
and asserts to check that the preinitialised values are never
actually used.

[originally from svn r8745]

--- a/tree234.c
+++ b/tree234.c
@@ -1182,6 +1182,7 @@
     /*
      * Search down the tree to find the split point.
      */
+    halves[0] = halves[1] = NULL;
     lparent = rparent = NULL;
     pki = -1;
     while (n) {
@@ -1273,6 +1274,8 @@
      */
     LOG(("  fell off bottom, lroot is %p, rroot is %p\n",
 	 halves[0], halves[1]));
+    assert(halves[0] != NULL);
+    assert(halves[1] != NULL);
     lparent->counts[pki] = rparent->counts[0] = 0;
     lparent->kids[pki] = rparent->kids[0] = NULL;
 
@@ -1475,6 +1478,7 @@
  * if not.)
  */
 
+#include <string.h>
 #include <stdarg.h>
 
 #define srealloc realloc