chiark / gitweb /
Cleanups from James H: a few missing statics, a precautionary cast
authorSimon Tatham <anakin@pobox.com>
Wed, 3 Aug 2005 12:44:51 +0000 (12:44 +0000)
committerSimon Tatham <anakin@pobox.com>
Wed, 3 Aug 2005 12:44:51 +0000 (12:44 +0000)
or two, a debugging fix, a couple of explicit initialisations of
variables that were previously read uninitialised, and a fix for a
whopping great big memory leak in Slant owing to me having
completely forgotten to write free_game().

[originally from svn r6159]

blackbox.c
dsf.c
slant.c
untangle.c
windows.c

index 89f673ee8ca16329ddc8252037261e73200f92bd..4f2270448057308c75deb49995d8f43cedd52011 100644 (file)
@@ -590,8 +590,7 @@ static int fire_laser_internal(game_state *state, int x, int y, int direction)
 
         if (isball(state, x, y, direction, LOOK_FORWARD)) {
             /* we're facing a ball; send back a reflection. */
-            debug(("Ball ahead of (%d, %d); HIT at (%d, %d), new grid 0x%x\n",
-                   x, y, xstart, ystart, GRID(state, xstart, ystart)));
+            debug(("Ball ahead of (%d, %d)", x, y));
             return LASER_HIT;         /* hit */
         }
 
@@ -1111,7 +1110,7 @@ static game_drawstate *game_new_drawstate(game_state *state)
     ds->w = state->w; ds->h = state->h;
     ds->grid = snewn((state->w+2)*(state->h+2), unsigned int);
     memset(ds->grid, 0, (state->w+2)*(state->h+2)*sizeof(unsigned int));
-    ds->started = 0;
+    ds->started = ds->reveal = 0;
     ds->flash_laserno = LASER_EMPTY;
 
     return ds;
diff --git a/dsf.c b/dsf.c
index 353bf1a4da7b68428e0d8b8d19ab1f9be61a5b09..a81bc3c008853a0a3b97e89898585da6eee4f6d4 100644 (file)
--- a/dsf.c
+++ b/dsf.c
@@ -4,6 +4,8 @@
  * worry about avoiding closed loops.
  */
 
+#include "puzzles.h"
+
 int dsf_canonify(int *dsf, int val)
 {
     int v2 = val;
diff --git a/slant.c b/slant.c
index bfd039e67f421cd7e1b29deb8beeedf9163ec2aa..06c1f51c15d9080b27d9773cd7d3ab07e0bd5d81 100644 (file)
--- a/slant.c
+++ b/slant.c
@@ -198,7 +198,7 @@ struct solver_scratch {
     int *dsf;
 };
 
-struct solver_scratch *new_scratch(int w, int h)
+static struct solver_scratch *new_scratch(int w, int h)
 {
     int W = w+1, H = h+1;
     struct solver_scratch *ret = snew(struct solver_scratch);
@@ -206,7 +206,7 @@ struct solver_scratch *new_scratch(int w, int h)
     return ret;
 }
 
-void free_scratch(struct solver_scratch *sc)
+static void free_scratch(struct solver_scratch *sc)
 {
     sfree(sc->dsf);
     sfree(sc);
@@ -629,6 +629,13 @@ static game_state *dup_game(game_state *state)
 
 static void free_game(game_state *state)
 {
+    sfree(state->soln);
+    assert(state->clues);
+    if (--state->clues->refcount <= 0) {
+        sfree(state->clues->clues);
+        sfree(state->clues->dsf);
+        sfree(state->clues);
+    }
     sfree(state);
 }
 
@@ -747,7 +754,7 @@ static char *solve_game(game_state *state, game_state *currstate,
        for (x = 0; x < w; x++) {
            int v = (soln[y*w+x] == bs ? -1 : +1);
            if (state->soln[y*w+x] != v) {
-               int len = sprintf(buf, ";%c%d,%d", v < 0 ? '\\' : '/', x, y);
+               int len = sprintf(buf, ";%c%d,%d", (int)(v < 0 ? '\\' : '/'), x, y);
                if (movelen + len >= movesize) {
                    movesize = movelen + len + 256;
                    move = sresize(move, movesize, char);
@@ -894,7 +901,7 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
                 v = -1;
         }
 
-        sprintf(buf, "%c%d,%d", v==-1 ? '\\' : v==+1 ? '/' : 'C', x, y);
+        sprintf(buf, "%c%d,%d", (int)(v==-1 ? '\\' : v==+1 ? '/' : 'C'), x, y);
         return dupstr(buf);
     }
 
@@ -996,6 +1003,7 @@ static game_drawstate *game_new_drawstate(game_state *state)
 
 static void game_free_drawstate(game_drawstate *ds)
 {
+    sfree(ds->todraw);
     sfree(ds->grid);
     sfree(ds);
 }
index 14a5c6c3c303356b79b8854ea7251d2735af4b1e..bb63eba776e2ff94e937c5101ee3653579a8c7bb 100644 (file)
@@ -218,7 +218,7 @@ typedef struct {
 #define greater64(i,j) ( (i).hi>(j).hi || ((i).hi==(j).hi && (i).lo>(j).lo))
 #define sign64(i) ((i).hi < 0 ? -1 : (i).hi==0 && (i).lo==0 ? 0 : +1)
 
-int64 mulu32to64(unsigned long x, unsigned long y)
+static int64 mulu32to64(unsigned long x, unsigned long y)
 {
     unsigned long a, b, c, d, t;
     int64 ret;
@@ -247,7 +247,7 @@ int64 mulu32to64(unsigned long x, unsigned long y)
     return ret;
 }
 
-int64 mul32to64(long x, long y)
+static int64 mul32to64(long x, long y)
 {
     int sign = +1;
     int64 ret;
@@ -276,7 +276,7 @@ int64 mul32to64(long x, long y)
     return ret;
 }
 
-int64 dotprod64(long a, long b, long p, long q)
+static int64 dotprod64(long a, long b, long p, long q)
 {
     int64 ab, pq;
 
index 08513d885999fd32a9786a91e31ec3889756a66a..f9af41ca0db24f0ae28385b9ef8ecdfb876866b5 100644 (file)
--- a/windows.c
+++ b/windows.c
@@ -417,7 +417,7 @@ void end_draw(frontend *fe)
 
 void deactivate_timer(frontend *fe)
 {
-    KillTimer(fe->hwnd, fe->timer);
+    if (fe->hwnd) KillTimer(fe->hwnd, fe->timer);
     fe->timer = 0;
 }
 
@@ -575,9 +575,11 @@ static frontend *new_window(HINSTANCE inst, char *game_id, char **error)
     find_help_file(fe);
 
     fe->inst = inst;
-    midend_new_game(fe->me);
 
     fe->timer = 0;
+    fe->hwnd = NULL;
+
+    midend_new_game(fe->me);
 
     fe->fonts = NULL;
     fe->nfonts = fe->fontsize = 0;