Fix a memory leak.
[sgt/puzzles] / rect.c
diff --git a/rect.c b/rect.c
index c78d9e0..7fff9af 100644 (file)
--- a/rect.c
+++ b/rect.c
@@ -34,6 +34,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
+#include <ctype.h>
 #include <math.h>
 
 #include "puzzles.h"
@@ -129,6 +130,29 @@ game_params *dup_params(game_params *params)
     return ret;
 }
 
+game_params *decode_params(char const *string)
+{
+    game_params *ret = default_params();
+
+    ret->w = ret->h = atoi(string);
+    while (*string && isdigit(*string)) string++;
+    if (*string == 'x') {
+        string++;
+        ret->h = atoi(string);
+    }
+
+    return ret;
+}
+
+char *encode_params(game_params *params)
+{
+    char data[256];
+
+    sprintf(data, "%dx%d", params->w, params->h);
+
+    return dupstr(data);
+}
+
 config_item *game_configure(game_params *params)
 {
     config_item *ret;
@@ -672,7 +696,7 @@ char *validate_seed(game_params *params, char *seed)
         } else if (n == '_') {
             /* do nothing */;
         } else if (n > '0' && n <= '9') {
-            squares += atoi(seed-1);
+            squares++;
             while (*seed >= '0' && *seed <= '9')
                 seed++;
         } else
@@ -1306,12 +1330,12 @@ void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
 
            if (HRANGE(state,x,y))
                 c |= index(state,hedge,x,y);
-           if (HRANGE(state,x+1,y))
-               c |= index(state,hedge,x+1,y) << 2;
+           if (HRANGE(state,x,y+1))
+               c |= index(state,hedge,x,y+1) << 2;
            if (VRANGE(state,x,y))
                c |= index(state,vedge,x,y) << 4;
-           if (VRANGE(state,x,y+1))
-               c |= index(state,vedge,x,y+1) << 6;
+           if (VRANGE(state,x+1,y))
+               c |= index(state,vedge,x+1,y) << 6;
            c |= index(state,corners,x,y) << 8;
            if (x+1 < state->w)
                c |= index(state,corners,x+1,y) << 10;
@@ -1333,6 +1357,7 @@ void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
         sfree(vedge);
    }
 
+    sfree(corners);
     sfree(correct);
 }