Environment-based configuration wasn't sensibly usable in games with
[sgt/puzzles] / slant.c
diff --git a/slant.c b/slant.c
index c562b48..1310018 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);
 }
 
@@ -727,9 +734,10 @@ static char *solve_game(game_state *state, game_state *currstate,
        if (ret != 1) {
            sfree(soln);
            if (ret == 0)
-               return "This puzzle is not self-consistent";
+               *error = "This puzzle is not self-consistent";
            else
-               return "Unable to find a unique solution for this puzzle";
+               *error = "Unable to find a unique solution for this puzzle";
+            return NULL;
        }
        free_soln = TRUE;
     }
@@ -747,7 +755,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 +902,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 +1004,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);
 }
@@ -1097,7 +1106,7 @@ static void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
                        game_state *state, int dir, game_ui *ui,
                        float animtime, float flashtime)
 {
-    int w = state->p.w, h = state->p.h, W = w+1 /*, H = h+1 */;
+    int w = state->p.w, h = state->p.h, W = w+1, H = h+1;
     int x, y;
     int flashing;
 
@@ -1116,11 +1125,11 @@ static void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
         * Draw any clues on the very edges (since normal tile
         * redraw won't draw the bits outside the grid boundary).
         */
-       for (y = 0; y < h; y++) {
+       for (y = 0; y < H; y++) {
            draw_clue(fe, ds, 0, y, state->clues->clues[y*W+0]);
            draw_clue(fe, ds, w, y, state->clues->clues[y*W+w]);
        }
-       for (x = 0; x < w; x++) {
+       for (x = 0; x < W; x++) {
            draw_clue(fe, ds, x, 0, state->clues->clues[0*W+x]);
            draw_clue(fe, ds, x, h, state->clues->clues[h*W+x]);
        }