chiark / gitweb /
Make the code base clean under -Wwrite-strings.
authorSimon Tatham <anakin@pobox.com>
Sun, 1 Oct 2017 13:45:12 +0000 (14:45 +0100)
committerSimon Tatham <anakin@pobox.com>
Sun, 1 Oct 2017 15:35:40 +0000 (16:35 +0100)
I've also added that warning option and -Werror to the build script,
so that I'll find out if I break this property in future.

35 files changed:
Buildscr
blackbox.c
cube.c
devel.but
dominosa.c
emcc.c
fifteen.c
filling.c
galaxies.c
grid.c
grid.h
gtk.c
guess.c
inertia.c
keen.c
latin.c
latin.h
loopy.c
map.c
midend.c
mines.c
osx.m
ps.c
puzzles.h
range.c
samegame.c
signpost.c
singles.c
sixteen.c
slant.c
solo.c
tents.c
twiddle.c
unequal.c
windows.c

index b8a585b43ea5c31dd74549b697f85d5a907cb03e..4a54d277ff90007264f5e30d21600f2778cb3516 100644 (file)
--- a/Buildscr
+++ b/Buildscr
@@ -25,7 +25,7 @@ in puzzles do echo '$#define VER "Version $(Version)"' >> version.h
 in puzzles do perl -i -pe 's/Unidentified build/$(Version)/' osx-info.plist
 
 # First build some local binaries, to run the icon build.
-in puzzles do perl mkfiles.pl -U
+in puzzles do perl mkfiles.pl -U CFLAGS='-Wwrite-strings -Werror'
 in puzzles do make
 
 # Now build the screenshots and icons.
@@ -45,7 +45,7 @@ in puzzles do ./mkauto.sh
 # Build the OS X .dmg archive.
 delegate osx
   in puzzles do make -f Makefile.osx clean
-  in puzzles do make -f Makefile.osx release VER=-DVER=$(Version)
+  in puzzles do make -f Makefile.osx release VER=-DVER=$(Version) XFLAGS='-Wwrite-strings -Werror'
   return puzzles/Puzzles.dmg
 enddelegate
 
@@ -56,7 +56,7 @@ in puzzles do mason.pl --args '{"version":"$(Version)","descfile":"gamedesc.txt"
 in puzzles do perl winiss.pl $(Version) gamedesc.txt > puzzles.iss
 ifneq "$(VISUAL_STUDIO)" "yes" then
   in puzzles with clangcl64 do Platform=x64 make -f Makefile.clangcl clean
-  in puzzles with clangcl64 do Platform=x64 make -f Makefile.clangcl VER=-DVER=$(Version)
+  in puzzles with clangcl64 do Platform=x64 make -f Makefile.clangcl VER=-DVER=$(Version) XFLAGS='-Wwrite-strings -Werror'
   # Code-sign the binaries, if the local bob config provides a script
   # to do so. We assume here that the script accepts an -i option to
   # provide a 'more info' URL, and an optional -n option to provide a
@@ -144,7 +144,7 @@ ifneq "$(JAVA_UNFINISHED)" "" in puzzles do perl mkfiles.pl
 
 # Build the Java applets.
 delegate nestedvm
-  in puzzles do make -f Makefile.nestedvm NESTEDVM="$$NESTEDVM" VER=-DVER=$(Version)
+  in puzzles do make -f Makefile.nestedvm NESTEDVM="$$NESTEDVM" VER=-DVER=$(Version) XFLAGS="-Wwrite-strings -Werror"
   return puzzles/*.jar
 enddelegate
 
@@ -154,7 +154,7 @@ enddelegate
 in puzzles do mkdir js # so we can tell output .js files from emcc*.js
 delegate emscripten
   in puzzles do make -f Makefile.emcc OUTPREFIX=js/ clean
-  in puzzles do make -f Makefile.emcc OUTPREFIX=js/
+  in puzzles do make -f Makefile.emcc OUTPREFIX=js/ XFLAGS="-Wwrite-strings -Werror"
   return puzzles/js/*.js
 enddelegate
 
index 829aaec4b67632db5db28ae6a4344558c54e008b..d92af92f2a81c0a4cc6234d9c4de214799e5a8da 100644 (file)
@@ -251,7 +251,7 @@ static const char *validate_desc(const game_params *params, const char *desc)
 {
     int nballs, dlen = strlen(desc), i;
     unsigned char *bmp;
-    char *ret;
+    const char *ret;
 
     /* the bitmap is 2+(nballs*2) long; the hex version is double that. */
     nballs = ((dlen/2)-2)/2;
diff --git a/cube.c b/cube.c
index f09f63d744a56568729703241c3f240e4d9cec98..2a79a81eef23ee204a2aa10bb5c3f24040e6d4be 100644 (file)
--- a/cube.c
+++ b/cube.c
@@ -238,7 +238,7 @@ static game_params *default_params(void)
 static int game_fetch_preset(int i, char **name, game_params **params)
 {
     game_params *ret = snew(game_params);
-    char *str;
+    const char *str;
 
     switch (i) {
       case 0:
index af6920240119c4369a4a2b58024a1b53517a42e3..131678c17b85e99273a125ddcd95016b28038d4f 100644 (file)
--- a/devel.but
+++ b/devel.but
@@ -3296,8 +3296,7 @@ visually activate and deactivate a redo button.
 \H{midend-serialise} \cw{midend_serialise()}
 
 \c void midend_serialise(midend *me,
-\c                       void (*write)(void *ctx, void *buf, int len),
-\c                       void *wctx);
+\c     void (*write)(void *ctx, const void *buf, int len), void *wctx);
 
 Calling this function causes the mid-end to convert its entire
 internal state into a long ASCII text string, and to pass that
index 14d854f6ae69a1c4a690aa943f5fa283a2a1f5bc..a072ac6168ee5db5c45af442f619a79dc3d9c0bd 100644 (file)
@@ -749,7 +749,7 @@ static const char *validate_desc(const game_params *params, const char *desc)
     int n = params->n, w = n+2, h = n+1, wh = w*h;
     int *occurrences;
     int i, j;
-    char *ret;
+    const char *ret;
 
     ret = NULL;
     occurrences = snewn(n+1, int);
diff --git a/emcc.c b/emcc.c
index dbb4ab974df5c022b13a11f423cf9d8d4acee89a..563fbe2799a02b0c67c4462cd6e7f97cc91e33d3 100644 (file)
--- a/emcc.c
+++ b/emcc.c
@@ -787,7 +787,7 @@ struct savefile_write_ctx {
     size_t pos;
 };
 
-static void savefile_write(void *vctx, void *buf, int len)
+static void savefile_write(void *vctx, const void *buf, int len)
 {
     struct savefile_write_ctx *ctx = (struct savefile_write_ctx *)vctx;
     if (ctx->buffer)
index 9c837564305807eaebcb4bc195876327fab43866..f749e96b24814888a14c5fefd35073fe38c0129e 100644 (file)
--- a/fifteen.c
+++ b/fifteen.c
@@ -273,7 +273,7 @@ static char *new_game_desc(const game_params *params, random_state *rs,
 static const char *validate_desc(const game_params *params, const char *desc)
 {
     const char *p;
-    char *err;
+    const char *err;
     int i, area;
     int *used;
 
index 6f775f4907dcc1ec5f4062d8fb6637cec0b929ab..7e71eb25b421a4d846cd41feea6468192eee9139 100644 (file)
--- a/filling.c
+++ b/filling.c
@@ -68,7 +68,7 @@
 
 static unsigned char verbose;
 
-static void printv(char *fmt, ...) {
+static void printv(const char *fmt, ...) {
 #ifndef PALM
     if (verbose) {
        va_list va;
index d10fc5d1753bbe4924006b97b0b4ff3832e162d4..5d7dbdf93321c714b52f618457c4b17c51071010 100644 (file)
@@ -667,7 +667,8 @@ static char *diff_game(const game_state *src, const game_state *dest,
                        int issolve)
 {
     int movelen = 0, movesize = 256, x, y, len;
-    char *move = snewn(movesize, char), buf[80], *sep = "";
+    char *move = snewn(movesize, char), buf[80];
+    const char *sep = "";
     char achar = issolve ? 'a' : 'A';
     space *sps, *spd;
 
@@ -1523,10 +1524,10 @@ static int dots_too_close(game_state *state)
 }
 
 static game_state *load_game(const game_params *params, const char *desc,
-                             char **why_r)
+                             const char **why_r)
 {
     game_state *state = blank_game(params->w, params->h);
-    char *why = NULL;
+    const char *why = NULL;
     int i, x, y, n;
     unsigned int df;
 
@@ -1572,7 +1573,7 @@ fail:
 
 static const char *validate_desc(const game_params *params, const char *desc)
 {
-    char *why = NULL;
+    const char *why = NULL;
     game_state *dummy = load_game(params, desc, &why);
     if (dummy) {
         free_game(dummy);
diff --git a/grid.c b/grid.c
index 4929b5c7d3c99547183543560a9180f815c555df..52648e5a92b9114f9d742bde44abc83c601266a1 100644 (file)
--- a/grid.c
+++ b/grid.c
@@ -1529,8 +1529,8 @@ static void grid_size_triangular(int width, int height,
     *yextent = height * vec_y;
 }
 
-static char *grid_validate_desc_triangular(grid_type type, int width,
-                                           int height, const char *desc)
+static const char *grid_validate_desc_triangular(grid_type type, int width,
+                                                 int height, const char *desc)
 {
     /*
      * Triangular grids: an absent description is valid (indicating
@@ -2855,8 +2855,9 @@ static char *grid_new_desc_penrose(grid_type type, int width, int height, random
     return dupstr(gd);
 }
 
-static char *grid_validate_desc_penrose(grid_type type, int width, int height,
-                                        const char *desc)
+static const char *grid_validate_desc_penrose(grid_type type,
+                                              int width, int height,
+                                              const char *desc)
 {
     int tilesize = PENROSE_TILESIZE, startsz, depth, xoff, yoff, aoff, inner_radius;
     double outer_radius;
@@ -3032,8 +3033,8 @@ char *grid_new_desc(grid_type type, int width, int height, random_state *rs)
     }
 }
 
-char *grid_validate_desc(grid_type type, int width, int height,
-                         const char *desc)
+const char *grid_validate_desc(grid_type type, int width, int height,
+                               const char *desc)
 {
     if (type == GRID_PENROSE_P2 || type == GRID_PENROSE_P3) {
         return grid_validate_desc_penrose(type, width, height, desc);
@@ -3048,7 +3049,7 @@ char *grid_validate_desc(grid_type type, int width, int height,
 
 grid *grid_new(grid_type type, int width, int height, const char *desc)
 {
-    char *err = grid_validate_desc(type, width, height, desc);
+    const char *err = grid_validate_desc(type, width, height, desc);
     if (err) assert(!"Invalid grid description.");
 
     return grid_news[type](width, height, desc);
diff --git a/grid.h b/grid.h
index fb8ac48790ac34b16e41d13e325875bad8513ac4..19079a44b8cf90666df6d9b8b0e9e19e8c670363 100644 (file)
--- a/grid.h
+++ b/grid.h
@@ -116,8 +116,8 @@ typedef enum grid_type { GRIDGEN_LIST(ENUM) GRID_TYPE_MAX } grid_type;
 /* Free directly after use if non-NULL. Will never contain an underscore
  * (so clients can safely use that as a separator). */
 char *grid_new_desc(grid_type type, int width, int height, random_state *rs);
-char *grid_validate_desc(grid_type type, int width, int height,
-                         const char *desc);
+const char *grid_validate_desc(grid_type type, int width, int height,
+                               const char *desc);
 
 grid *grid_new(grid_type type, int width, int height, const char *desc);
 
diff --git a/gtk.c b/gtk.c
index 089143c7c0cb7ea7a7f2929ece33a655f5f4cd9c..37ba8078e20d5858eb25659cf34336cb2f57cece 100644 (file)
--- a/gtk.c
+++ b/gtk.c
@@ -2168,7 +2168,7 @@ static void filesel_ok(GtkButton *button, gpointer data)
     fe->filesel_name = dupstr(name);
 }
 
-static char *file_selector(frontend *fe, char *title, int save)
+static char *file_selector(frontend *fe, const char *title, int save)
 {
     GtkWidget *filesel =
         gtk_file_selection_new(title);
@@ -2199,7 +2199,7 @@ static char *file_selector(frontend *fe, char *title, int save)
 
 #else
 
-static char *file_selector(frontend *fe, char *title, int save)
+static char *file_selector(frontend *fe, const char *title, int save)
 {
     char *filesel_name = NULL;
 
@@ -2231,7 +2231,7 @@ struct savefile_write_ctx {
     int error;
 };
 
-static void savefile_write(void *wctx, void *buf, int len)
+static void savefile_write(void *wctx, const void *buf, int len)
 {
     struct savefile_write_ctx *ctx = (struct savefile_write_ctx *)wctx;
     if (fwrite(buf, 1, len, ctx->fp) < len)
@@ -2396,7 +2396,7 @@ static void menu_about_event(GtkMenuItem *menuitem, gpointer data)
 }
 
 static GtkWidget *add_menu_ui_item(
-    frontend *fe, GtkContainer *cont, char *text, int action,
+    frontend *fe, GtkContainer *cont, const char *text, int action,
     int accel_key, int accel_keyqual)
 {
     GtkWidget *menuitem = gtk_menu_item_new_with_label(text);
@@ -2928,7 +2928,7 @@ int main(int argc, char **argv)
     int soln = FALSE, colour = FALSE;
     float scale = 1.0F;
     float redo_proportion = 0.0F;
-    char *savefile = NULL, *savesuffix = NULL;
+    const char *savefile = NULL, *savesuffix = NULL;
     char *arg = NULL;
     int argtype = ARG_EITHER;
     char *screenshot_file = NULL;
diff --git a/guess.c b/guess.c
index 14e2d9013dddddd657876c0f3fc927ac7af31d72..a14f3bdc4de61852582f6e2f700c4c39fa5bfe33 100644 (file)
--- a/guess.c
+++ b/guess.c
@@ -74,7 +74,7 @@ static game_params *dup_params(const game_params *params)
 }
 
 static const struct {
-    char *name;
+    const char *name;
     game_params params;
 } guess_presets[] = {
     {"Standard", {6, 4, 10, FALSE, TRUE}},
@@ -440,7 +440,8 @@ static void free_ui(game_ui *ui)
 
 static char *encode_ui(const game_ui *ui)
 {
-    char *ret, *p, *sep;
+    char *ret, *p;
+    const char *sep;
     int i;
 
     /*
@@ -614,7 +615,8 @@ static int mark_pegs(pegrow guess, const pegrow solution, int ncols)
 
 static char *encode_move(const game_state *from, game_ui *ui)
 {
-    char *buf, *p, *sep;
+    char *buf, *p;
+    const char *sep;
     int len, i;
 
     len = ui->curr_pegs->npegs * 20 + 2;
index 6c64fc0ca9f8f911cb3fa3d5f0d86bb98d0a098b..ad58bd2ae96012b30cb065d59ca5376272849bb2 100644 (file)
--- a/inertia.c
+++ b/inertia.c
@@ -738,7 +738,8 @@ static char *solve_game(const game_state *state, const game_state *currstate,
     int *unvisited;
     int circuitlen, circuitsize;
     int head, tail, pass, i, j, n, x, y, d, dd;
-    char *err, *soln, *p;
+    const char *err;
+    char *soln, *p;
 
     /*
      * Before anything else, deal with the special case in which
diff --git a/keen.c b/keen.c
index 2acbea91fc317c6839b13fe76c3fdcdaee34353b..ec7af12985c46d5ea4da5339b4f40294e8e4f67b 100644 (file)
--- a/keen.c
+++ b/keen.c
@@ -727,7 +727,7 @@ static char *encode_block_structure(char *p, int w, int *dsf)
     return q;
 }
 
-static char *parse_block_structure(const char **p, int w, int *dsf)
+static const char *parse_block_structure(const char **p, int w, int *dsf)
 {
     int a = w*w;
     int pos = 0;
@@ -1207,7 +1207,7 @@ static const char *validate_desc(const game_params *params, const char *desc)
 {
     int w = params->w, a = w*w;
     int *dsf;
-    char *ret;
+    const char *ret;
     const char *p = desc;
     int i;
 
diff --git a/latin.c b/latin.c
index 03d78aff1f6c798f9d0fa24dc353df08b057488b..50fae3cfeab6f855169e92a19e614f898a9173b9 100644 (file)
--- a/latin.c
+++ b/latin.c
@@ -73,7 +73,7 @@ void latin_solver_place(struct latin_solver *solver, int x, int y, int n)
 
 int latin_solver_elim(struct latin_solver *solver, int start, int step
 #ifdef STANDALONE_SOLVER
-                     , char *fmt, ...
+                     , const char *fmt, ...
 #endif
                      )
 {
@@ -150,7 +150,7 @@ int latin_solver_set(struct latin_solver *solver,
                      struct latin_solver_scratch *scratch,
                      int start, int step1, int step2
 #ifdef STANDALONE_SOLVER
-                     , char *fmt, ...
+                     , const char *fmt, ...
 #endif
                      )
 {
@@ -499,7 +499,7 @@ int latin_solver_forcing(struct latin_solver *solver,
                                 (xt == x || yt == y)) {
 #ifdef STANDALONE_SOLVER
                                 if (solver_show_working) {
-                                    char *sep = "";
+                                    const char *sep = "";
                                     int xl, yl;
                                     printf("%*sforcing chain, %s at ends of ",
                                            solver_recurse_depth*4, "",
@@ -775,7 +775,7 @@ static int latin_solver_recurse
 
 #ifdef STANDALONE_SOLVER
         if (solver_show_working) {
-            char *sep = "";
+            const char *sep = "";
             printf("%*srecursing on (%d,%d) [",
                    solver_recurse_depth*4, "", x+1, y+1);
             for (i = 0; i < j; i++) {
diff --git a/latin.h b/latin.h
index 4b09f16ce16051e3c28a25979e9842f87e300019..e13050e9a8c074d9b5b279d30ce6fc45b13b5113 100644 (file)
--- a/latin.h
+++ b/latin.h
@@ -39,7 +39,7 @@ void latin_solver_place(struct latin_solver *solver, int x, int y, int n);
 /* Positional elimination. */
 int latin_solver_elim(struct latin_solver *solver, int start, int step
 #ifdef STANDALONE_SOLVER
-                      , char *fmt, ...
+                      , const char *fmt, ...
 #endif
                       );
 
@@ -49,7 +49,7 @@ int latin_solver_set(struct latin_solver *solver,
                      struct latin_solver_scratch *scratch,
                      int start, int step1, int step2
 #ifdef STANDALONE_SOLVER
-                     , char *fmt, ...
+                     , const char *fmt, ...
 #endif
                      );
 
diff --git a/loopy.c b/loopy.c
index 32f38ce0eb87c0200885119f45bdf28c85e2c3f4..5f1940e945f0228e1ed508513be412a285804618 100644 (file)
--- a/loopy.c
+++ b/loopy.c
@@ -295,7 +295,7 @@ static grid_type grid_types[] = { GRIDLIST(GRID_GRIDTYPE) };
 #define NUM_GRID_TYPES (sizeof(grid_types) / sizeof(grid_types[0]))
 static const struct {
     int amin, omin;
-    char *aerr, *oerr;
+    const char *aerr, *oerr;
 } grid_size_limits[] = { GRIDLIST(GRID_SIZES) };
 
 /* Generates a (dynamically allocated) new grid, according to the
@@ -760,7 +760,8 @@ static const char *validate_desc(const game_params *params, const char *desc)
 {
     int count = 0;
     grid *g;
-    char *grid_desc, *ret;
+    char *grid_desc;
+    const char *ret;
 
     /* It's pretty inefficient to do this just for validation. All we need to
      * know is the precise number of faces. */
diff --git a/map.c b/map.c
index 4796f8e60b5a3bb555106701a4f87034dd75198f..4da834ac65859434fa9a68981ac408cbbb88f427 100644 (file)
--- a/map.c
+++ b/map.c
@@ -873,7 +873,7 @@ static const char colnames[FOUR] = { 'R', 'Y', 'G', 'B' };
 static int place_colour(struct solver_scratch *sc,
                        int *colouring, int index, int colour
 #ifdef SOLVER_DIAGNOSTICS
-                        , char *verb
+                        , const char *verb
 #endif
                         )
 {
@@ -920,7 +920,7 @@ static char *colourset(char *buf, int set)
 {
     int i;
     char *p = buf;
-    char *sep = "";
+    const char *sep = "";
 
     for (i = 0; i < FOUR; i++)
         if (set & (1 << i)) {
@@ -1214,7 +1214,8 @@ static int map_solver(struct solver_scratch *sc,
                                 (sc->possible[k] & currc)) {
 #ifdef SOLVER_DIAGNOSTICS
                                 if (verbose) {
-                                    char buf[80], *sep = "";
+                                    char buf[80];
+                                    const char *sep = "";
                                     int r;
 
                                     printf("%*sforcing chain, colour %s, ",
@@ -1699,8 +1700,8 @@ static char *new_game_desc(const game_params *params, random_state *rs,
     return ret;
 }
 
-static char *parse_edge_list(const game_params *params, const char **desc,
-                             int *map)
+static const char *parse_edge_list(const game_params *params,
+                                   const char **desc, int *map)
 {
     int w = params->w, h = params->h, wh = w*h, n = params->n;
     int i, k, pos, state;
@@ -1781,7 +1782,7 @@ static const char *validate_desc(const game_params *params, const char *desc)
     int w = params->w, h = params->h, wh = w*h, n = params->n;
     int area;
     int *map;
-    char *ret;
+    const char *ret;
 
     map = snewn(2*wh, int);
     ret = parse_edge_list(params, &desc, map);
@@ -1841,7 +1842,7 @@ static game_state *new_game(midend *me, const game_params *params,
     p = desc;
 
     {
-       char *ret;
+       const char *ret;
        ret = parse_edge_list(params, &p, state->map->map);
        assert(!ret);
     }
index cf1a5ae4ecd3fb67c01309b83e6e730798476c78..1a65121d9c03381a55630804cc76bfb8341e2102 100644 (file)
--- a/midend.c
+++ b/midend.c
@@ -118,7 +118,7 @@ struct deserialise_data {
  */
 static const char *midend_deserialise_internal(
     midend *me, int (*read)(void *ctx, void *buf, int len), void *rctx,
-    char *(*check)(void *ctx, midend *, const struct deserialise_data *),
+    const char *(*check)(void *ctx, midend *, const struct deserialise_data *),
     void *cctx);
 
 void midend_reset_tilesize(midend *me)
@@ -384,7 +384,7 @@ void midend_force_redraw(midend *me)
     midend_redraw(me);
 }
 
-static void newgame_serialise_write(void *ctx, void *buf, int len)
+static void newgame_serialise_write(void *ctx, const void *buf, int len)
 {
     midend *const me = ctx;
     int new_len;
@@ -547,7 +547,7 @@ struct newgame_undo_deserialise_check_ctx {
     int refused;
 };
 
-static char *newgame_undo_deserialise_check(
+static const char *newgame_undo_deserialise_check(
     void *vctx, midend *me, const struct deserialise_data *data)
 {
     struct newgame_undo_deserialise_check_ctx *ctx =
@@ -1333,7 +1333,8 @@ void midend_supersede_game_desc(midend *me, const char *desc,
 
 config_item *midend_get_config(midend *me, int which, char **wintitle)
 {
-    char *titlebuf, *parstr, *rest;
+    char *titlebuf, *parstr;
+    const char *rest;
     config_item *ret;
     char sep;
 
@@ -1765,7 +1766,7 @@ char *midend_rewrite_statusbar(midend *me, const char *text)
 #define SERIALISE_VERSION "1"
 
 void midend_serialise(midend *me,
-                      void (*write)(void *ctx, void *buf, int len),
+                      void (*write)(void *ctx, const void *buf, int len),
                       void *wctx)
 {
     int i;
@@ -1781,7 +1782,7 @@ void midend_serialise(midend *me,
      */
 #define wr(h,s) do { \
     char hbuf[80]; \
-    char *str = (s); \
+    const char *str = (s); \
     char lbuf[9];                               \
     copy_left_justified(lbuf, sizeof(lbuf), h); \
     sprintf(hbuf, "%s:%d:", lbuf, (int)strlen(str)); \
@@ -1922,7 +1923,7 @@ void midend_serialise(midend *me,
  */
 static const char *midend_deserialise_internal(
     midend *me, int (*read)(void *ctx, void *buf, int len), void *rctx,
-    char *(*check)(void *ctx, midend *, const struct deserialise_data *data),
+    const char *(*check)(void *ctx, midend *, const struct deserialise_data *),
     void *cctx)
 {
     struct deserialise_data data;
@@ -1932,7 +1933,7 @@ static const char *midend_deserialise_internal(
 
     char *val = NULL;
     /* Initially all errors give the same report */
-    char *ret = "Data does not appear to be a saved game file";
+    const char *ret = "Data does not appear to be a saved game file";
 
     data.seed = data.parstr = data.desc = data.privdesc = NULL;
     data.auxinfo = data.uistr = data.cparstr = NULL;
@@ -2309,7 +2310,7 @@ const char *identify_game(char **name,
 
     char *val = NULL;
     /* Initially all errors give the same report */
-    char *ret = "Data does not appear to be a saved game file";
+    const char *ret = "Data does not appear to be a saved game file";
 
     *name = NULL;
 
diff --git a/mines.c b/mines.c
index 6304668d36482581fa742a5621628ef207c25041..6a854c6aac364c098c0659d95c01640ec8b80f9d 100644 (file)
--- a/mines.c
+++ b/mines.c
@@ -2558,7 +2558,7 @@ uncover:
                 * can.
                 */
                char *p = buf;
-               char *sep = "";
+               const char *sep = "";
 
                for (dy = -1; dy <= +1; dy++)
                    for (dx = -1; dx <= +1; dx++)
diff --git a/osx.m b/osx.m
index 9403faedc9399501f2f074ede58db110282a0236..daa4af1f094c8d6efe18716e35742c05b532a2e1 100644 (file)
--- a/osx.m
+++ b/osx.m
@@ -152,7 +152,7 @@ void get_random_seed(void **randseed, int *randseedsize)
     *randseedsize = sizeof(time_t);
 }
 
-static void savefile_write(void *wctx, void *buf, int len)
+static void savefile_write(void *wctx, const void *buf, int len)
 {
     FILE *fp = (FILE *)wctx;
     fwrite(buf, 1, len, fp);
diff --git a/ps.c b/ps.c
index 6ec8aacc19f90e2a10106ab107c979bc8a9dff55..ac021aa80a58991d790d88ed34544f5ae2e4f1ce 100644 (file)
--- a/ps.c
+++ b/ps.c
@@ -21,7 +21,7 @@ struct psdata {
     drawing *drawing;
 };
 
-static void ps_printf(psdata *ps, char *fmt, ...)
+static void ps_printf(psdata *ps, const char *fmt, ...)
 {
     va_list ap;
 
@@ -73,7 +73,7 @@ static void ps_fill(psdata *ps, int colour)
     }
 }
 
-static void ps_setcolour_internal(psdata *ps, int colour, char *suffix)
+static void ps_setcolour_internal(psdata *ps, int colour, const char *suffix)
 {
     int hatch;
     float r, g, b;
index 11542a58e76798bb8a794a47294ee75b3d5faea8..40f5bcbce3a45bb2172ff8d5de43b42fb958a8e0 100644 (file)
--- a/puzzles.h
+++ b/puzzles.h
@@ -325,7 +325,7 @@ void midend_supersede_game_desc(midend *me, const char *desc,
                                 const char *privdesc);
 char *midend_rewrite_statusbar(midend *me, const char *text);
 void midend_serialise(midend *me,
-                      void (*write)(void *ctx, void *buf, int len),
+                      void (*write)(void *ctx, const void *buf, int len),
                       void *wctx);
 const char *midend_deserialise(midend *me,
                                int (*read)(void *ctx, void *buf, int len),
diff --git a/range.c b/range.c
index aef74538125f3345355b1fe02ead6e61ce8fbc34..41c6a352d36fa533991bf18f71ca33f55dce6a57 100644 (file)
--- a/range.c
+++ b/range.c
@@ -66,7 +66,7 @@
 
 #define setmember(obj, field) ( (obj) . field = field )
 
-static char *nfmtstr(int n, char *fmt, ...) {
+static char *nfmtstr(int n, const char *fmt, ...) {
     va_list va;
     char *ret = snewn(n+1, char);
     va_start(va, fmt);
index 8b3106272de8e3b102d6f540ca53a12ab86869ab..d7d06764bfa40f5814c6ed9b492b9e01218fb1bb 100644 (file)
@@ -1108,7 +1108,8 @@ static void game_changed_state(game_ui *ui, const game_state *oldstate,
 static char *sel_movedesc(game_ui *ui, const game_state *state)
 {
     int i;
-    char *ret, *sep, buf[80];
+    char *ret, buf[80];
+    const char *sep;
     int retlen, retsize;
 
     retsize = 256;
index 9c1c9ba38ca7130f4aae7919ef178d6954851740..72f3ab201f16943ca52cd1752af1bac120ec09fe 100644 (file)
@@ -497,10 +497,11 @@ static void free_game(game_state *state)
 }
 
 static void unpick_desc(const game_params *params, const char *desc,
-                        game_state **sout, char **mout)
+                        game_state **sout, const char **mout)
 {
     game_state *state = blank_game(params->w, params->h);
-    char *msg = NULL, c;
+    const char *msg = NULL;
+    char c;
     int num = 0, i = 0;
 
     while (*desc) {
@@ -845,7 +846,7 @@ generate:
 
 static const char *validate_desc(const game_params *params, const char *desc)
 {
-    char *ret = NULL;
+    const char *ret = NULL;
 
     unpick_desc(params, desc, NULL, &ret);
     return ret;
index c88c6c5c241b672a43de35eb2ca8273aa4b0878e..5929d829327acc937a16f9847b40c4b676e7c27c 100644 (file)
--- a/singles.c
+++ b/singles.c
@@ -330,10 +330,10 @@ static int c2n(char c) {
 }
 
 static void unpick_desc(const game_params *params, const char *desc,
-                        game_state **sout, char **mout)
+                        game_state **sout, const char **mout)
 {
     game_state *state = blank_game(params->w, params->h);
-    char *msg = NULL;
+    const char *msg = NULL;
     int num = 0, i = 0;
 
     if (strlen(desc) != state->n) {
@@ -1412,7 +1412,7 @@ randomise:
 
 static const char *validate_desc(const game_params *params, const char *desc)
 {
-    char *ret = NULL;
+    const char *ret = NULL;
 
     unpick_desc(params, desc, NULL, &ret);
     return ret;
index 74f221aebc1b3d7e313de574bf50dec10737bf9e..70cc43339a4a67b78fe2bada9c8c29446e824c63 100644 (file)
--- a/sixteen.c
+++ b/sixteen.c
@@ -398,8 +398,7 @@ static char *new_game_desc(const game_params *params, random_state *rs,
 
 static const char *validate_desc(const game_params *params, const char *desc)
 {
-    const char *p;
-    char *err;
+    const char *p, *err;
     int i, area;
     int *used;
 
diff --git a/slant.c b/slant.c
index 7fe5a6aa810628c25d9aea888ac7fd69cbed3988..3fd66115b15f36aeeaedb30a9c8950c0f0575ea7 100644 (file)
--- a/slant.c
+++ b/slant.c
@@ -413,7 +413,7 @@ static void fill_square(int w, int h, int x, int y, int v,
 }
 
 static int vbitmap_clear(int w, int h, struct solver_scratch *sc,
-                         int x, int y, int vbits, char *reason, ...)
+                         int x, int y, int vbits, const char *reason, ...)
 {
     int done_something = FALSE;
     int vbit;
@@ -734,7 +734,7 @@ static int slant_solve(int w, int h, const signed char *clues,
                int fs, bs, v;
                int c1, c2;
 #ifdef SOLVER_DIAGNOSTICS
-               char *reason = "<internal error>";
+               const char *reason = "<internal error>";
 #endif
 
                if (soln[y*w+x])
diff --git a/solo.c b/solo.c
index 3d1f86d211052eb2e562b545b3a2ec5e92e5d503..ef2852f1d9632ad2c6c59c8ae39d201dfba7b483 100644 (file)
--- a/solo.c
+++ b/solo.c
@@ -299,9 +299,9 @@ static game_params *dup_params(const game_params *params)
 static int game_fetch_preset(int i, char **name, game_params **params)
 {
     static struct {
-        char *title;
+        const char *title;
         game_params params;
-    } presets[] = {
+    } const presets[] = {
         { "2x2 Trivial", { 2, 2, SYMM_ROT2, DIFF_BLOCK, DIFF_KMINMAX, FALSE, FALSE } },
         { "2x3 Basic", { 2, 3, SYMM_ROT2, DIFF_SIMPLE, DIFF_KMINMAX, FALSE, FALSE } },
         { "3x3 Trivial", { 3, 3, SYMM_ROT2, DIFF_BLOCK, DIFF_KMINMAX, FALSE, FALSE } },
@@ -831,19 +831,20 @@ static void solver_place(struct solver_usage *usage, int x, int y, int n)
  */
 struct solver_scratch;
 static int solver_elim(struct solver_usage *usage, int *indices,
-                       char *fmt, ...) __attribute__((format(printf,3,4)));
+                       const char *fmt, ...)
+    __attribute__((format(printf,3,4)));
 static int solver_intersect(struct solver_usage *usage,
-                            int *indices1, int *indices2, char *fmt, ...)
+                            int *indices1, int *indices2, const char *fmt, ...)
     __attribute__((format(printf,4,5)));
 static int solver_set(struct solver_usage *usage,
                       struct solver_scratch *scratch,
-                      int *indices, char *fmt, ...)
+                      int *indices, const char *fmt, ...)
     __attribute__((format(printf,4,5)));
 #endif
 
 static int solver_elim(struct solver_usage *usage, int *indices
 #ifdef STANDALONE_SOLVER
-                       , char *fmt, ...
+                       , const char *fmt, ...
 #endif
                        )
 {
@@ -907,7 +908,7 @@ static int solver_elim(struct solver_usage *usage, int *indices
 static int solver_intersect(struct solver_usage *usage,
                             int *indices1, int *indices2
 #ifdef STANDALONE_SOLVER
-                            , char *fmt, ...
+                            , const char *fmt, ...
 #endif
                             )
 {
@@ -985,7 +986,7 @@ static int solver_set(struct solver_usage *usage,
                       struct solver_scratch *scratch,
                       int *indices
 #ifdef STANDALONE_SOLVER
-                      , char *fmt, ...
+                      , const char *fmt, ...
 #endif
                       )
 {
@@ -1351,7 +1352,7 @@ static int solver_forcing(struct solver_usage *usage,
                                                  (ondiag1(yt*cr+xt) && ondiag1(y*cr+x)))))) {
 #ifdef STANDALONE_SOLVER
                                 if (solver_show_working) {
-                                    char *sep = "";
+                                    const char *sep = "";
                                     int xl, yl;
                                     printf("%*sforcing chain, %d at ends of ",
                                            solver_recurse_depth*4, "", orign);
@@ -2516,7 +2517,7 @@ static void solver(int cr, struct block_structure *blocks,
 
 #ifdef STANDALONE_SOLVER
            if (solver_show_working) {
-               char *sep = "";
+               const char *sep = "";
                printf("%*srecursing on (%d,%d) [",
                       solver_recurse_depth*4, "", x + 1, y + 1);
                for (i = 0; i < j; i++) {
@@ -3154,7 +3155,8 @@ static int symmetries(const game_params *params, int x, int y,
 static char *encode_solve_move(int cr, digit *grid)
 {
     int i, len;
-    char *ret, *p, *sep;
+    char *ret, *p;
+    const char *sep;
 
     /*
      * It's surprisingly easy to work out _exactly_ how long this
diff --git a/tents.c b/tents.c
index 0057aed5dbce9038b050e605bbbd59e1216e1b41..48d420e5b70c53bee4972b31f07d75c10f024b11 100644 (file)
--- a/tents.c
+++ b/tents.c
@@ -1561,7 +1561,8 @@ static char *interpret_move(const game_state *state, game_ui *ui,
     if ((IS_MOUSE_DRAG(button) || IS_MOUSE_RELEASE(button)) &&
         ui->drag_button > 0) {
         int xmin, ymin, xmax, ymax;
-        char *buf, *sep;
+        char *buf;
+        const char *sep;
         int buflen, bufsize, tmplen;
 
         x = FROMCOORD(x);
index fb8f70062799b0eb38e599d8dd6220f706cf3b33..1f2825f2d82e6187b1f39a00fa2811aaf7dc5fab 100644 (file)
--- a/twiddle.c
+++ b/twiddle.c
@@ -80,9 +80,9 @@ static game_params *dup_params(const game_params *params)
 static int game_fetch_preset(int i, char **name, game_params **params)
 {
     static struct {
-        char *title;
+        const char *title;
         game_params params;
-    } presets[] = {
+    } const presets[] = {
         { "3x3 rows only", { 3, 3, 2, TRUE, FALSE } },
         { "3x3 normal", { 3, 3, 2, FALSE, FALSE } },
         { "3x3 orientable", { 3, 3, 2, FALSE, TRUE } },
index ccb00dd2993ba69628c7bc764a9b8cedc7128ea6..12d84bf80a41f79058651915b649cd84fb0a8cda 100644 (file)
--- a/unequal.c
+++ b/unequal.c
@@ -1195,12 +1195,12 @@ generate:
 }
 
 static game_state *load_game(const game_params *params, const char *desc,
-                             char **why_r)
+                             const char **why_r)
 {
     game_state *state = blank_game(params->order, params->adjacent);
     const char *p = desc;
     int i = 0, n, o = params->order, x, y;
-    char *why = NULL;
+    const char *why = NULL;
 
     while (*p) {
         while (*p >= 'a' && *p <= 'z') {
@@ -1293,7 +1293,7 @@ static game_state *new_game(midend *me, const game_params *params,
 
 static const char *validate_desc(const game_params *params, const char *desc)
 {
-    char *why = NULL;
+    const char *why = NULL;
     game_state *dummy = load_game(params, desc, &why);
     if (dummy) {
         free_game(dummy);
index 0a43c5d2785c93caa23cc6808251d34d446f049e..8e5b40650d8a87386880c92ab084189eb1c803ab 100644 (file)
--- a/windows.c
+++ b/windows.c
@@ -1551,7 +1551,7 @@ static frontend *frontend_new(HINSTANCE inst)
     return fe;
 }
 
-static void savefile_write(void *wctx, void *buf, int len)
+static void savefile_write(void *wctx, const void *buf, int len)
 {
     FILE *fp = (FILE *)wctx;
     fwrite(buf, 1, len, fp);