Fix warnings generated by gcc 4.6.0 about variables set but not

thereafter read. Most of these changes are just removal of pointless
stuff or trivial reorganisations; one change is actually substantive,
and fixes a bug in Keen's clue selection (the variable 'bad' was
unreferenced not because I shouldn't have set it, but because I
_should_ have referenced it!).

[originally from svn r9164]
This commit is contained in:
Simon Tatham
2011-05-04 18:22:14 +00:00
parent 4bab5e531b
commit 2efc77d2fd
14 changed files with 31 additions and 54 deletions

View File

@ -513,7 +513,6 @@ static int island_impossible(struct island *is, int strict)
{
int curr = island_countbridges(is), nspc = is->count - curr, nsurrspc;
int i, poss;
grid_type v;
struct island *is_orth;
if (nspc < 0) {
@ -533,7 +532,6 @@ static int island_impossible(struct island *is, int strict)
int ifree, dx = is->adj.points[i].dx;
if (!is->adj.points[i].off) continue;
v = GRID(is->state, is->adj.points[i].x, is->adj.points[i].y);
poss = POSSIBLES(is->state, dx,
is->adj.points[i].x, is->adj.points[i].y);
if (poss == 0) continue;

2
cube.c
View File

@ -1546,7 +1546,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
int *pkey, *gkey;
float t[3];
float angle;
game_state *newstate;
int square;
draw_rect(dr, 0, 0, XSIZE(GRID_SCALE, bb, state->solid),
@ -1580,7 +1579,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
pkey = state->spkey;
gkey = state->sgkey;
}
newstate = state;
state = oldstate;
for (i = 0; i < state->grid->nsquares; i++) {

View File

@ -1210,10 +1210,9 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
game_state *state, int dir, game_ui *ui,
float animtime, float flashtime)
{
int i, new_move, last_go;
int i, new_move;
new_move = (state->next_go != ds->next_go) || !ds->started;
last_go = (state->next_go == state->params.nguesses-1);
if (!ds->started) {
draw_rect(dr, 0, 0, ds->w, ds->h, COL_BACKGROUND);

5
keen.c
View File

@ -995,7 +995,7 @@ done
/* didn't find a nice one, use a nasty one */
for (i = 0; i < a; i++) {
j = order[i];
if (singletons[j] & good) {
if (singletons[j] & bad) {
clues[j] = clue;
singletons[j] = 0;
break;
@ -1188,7 +1188,6 @@ static game_state *new_game(midend *me, game_params *params, char *desc)
{
int w = params->w, a = w*w;
game_state *state = snew(game_state);
char *err;
const char *p = desc;
int i;
@ -1197,7 +1196,7 @@ static game_state *new_game(midend *me, game_params *params, char *desc)
state->clues->refcount = 1;
state->clues->w = w;
state->clues->dsf = snew_dsf(a);
err = parse_block_structure(&p, w, state->clues->dsf);
parse_block_structure(&p, w, state->clues->dsf);
assert(*p == ',');
p++;

View File

@ -1402,6 +1402,7 @@ static int strip_unused_nums(game_state *state)
}
}
}
debug(("Stripped %d unused numbers.\n", n));
return n;
}
@ -1475,7 +1476,7 @@ static char *new_game_desc(game_params *params, random_state *rs,
char **aux, int interactive)
{
game_state *news = new_state(params), *copys;
int nsol, i, j, run, x, y, wh = params->w*params->h, num;
int i, j, run, x, y, wh = params->w*params->h, num;
char *ret, *p;
int *numindices;
@ -1499,8 +1500,7 @@ static char *new_game_desc(game_params *params, random_state *rs,
/* Take a copy, remove numbers we didn't use and check there's
* still a unique solution; if so, use the copy subsequently. */
copys = dup_game(news);
nsol = strip_unused_nums(copys);
debug(("Stripped %d unused numbers.\n", nsol));
strip_unused_nums(copys);
if (!puzzle_is_good(copys, params->difficulty)) {
debug(("Stripped grid is not good, reverting.\n"));
free_game(copys);

View File

@ -3548,7 +3548,6 @@ static void game_redraw_line(drawing *dr, game_drawstate *ds,
grid *g = state->game_grid;
grid_edge *e = g->edges + i;
int x1, x2, y1, y2;
int xmin, ymin, xmax, ymax;
int line_colour;
if (state->line_errors[i])
@ -3568,11 +3567,6 @@ static void game_redraw_line(drawing *dr, game_drawstate *ds,
grid_to_screen(ds, g, e->dot1->x, e->dot1->y, &x1, &y1);
grid_to_screen(ds, g, e->dot2->x, e->dot2->y, &x2, &y2);
xmin = min(x1, x2);
xmax = max(x1, x2);
ymin = min(y1, y2);
ymax = max(y1, y2);
if (line_colour == COL_FAINT) {
static int draw_faint_lines = -1;
if (draw_faint_lines < 0) {

View File

@ -1046,7 +1046,7 @@ static int solve_rowcols(game_state *state, rowcolfn fn)
static int solve_force(game_state *state)
{
int x, y, i, which, didsth = 0;
int i, which, didsth = 0;
unsigned long f;
for (i = 0; i < state->wh; i++) {
@ -1062,7 +1062,6 @@ static int solve_force(game_state *state)
if (f == (GS_NOTNEGATIVE|GS_NOTNEUTRAL))
which = POSITIVE;
if (which != -1) {
x = i%state->w; y = i/state->w;
if (solve_set(state, i, which, "forced by flags", NULL) < 0)
return -1;
didsth = 1;
@ -1073,7 +1072,7 @@ static int solve_force(game_state *state)
static int solve_neither(game_state *state)
{
int x, y, i, j, didsth = 0;
int i, j, didsth = 0;
for (i = 0; i < state->wh; i++) {
if (state->flags[i] & GS_SET) continue;
@ -1084,7 +1083,6 @@ static int solve_neither(game_state *state)
(state->flags[j] & GS_NOTPOSITIVE)) ||
((state->flags[i] & GS_NOTNEGATIVE) &&
(state->flags[j] & GS_NOTNEGATIVE))) {
x = i%state->w; y = i/state->w;
if (solve_set(state, i, NEUTRAL, "neither tile magnet", NULL) < 0)
return -1;
didsth = 1;
@ -1494,7 +1492,7 @@ static int solve_unnumbered(game_state *state)
static int lay_dominoes(game_state *state, random_state *rs, int *scratch)
{
int n, i, ret = 0, x, y, nlaid = 0, n_initial_neutral;
int n, i, ret = 0, nlaid = 0, n_initial_neutral;
for (i = 0; i < state->wh; i++) {
scratch[i] = i;
@ -1513,8 +1511,7 @@ static int lay_dominoes(game_state *state, random_state *rs, int *scratch)
/* ...and lay a domino if we can. */
x = i%state->w; y = i/state->w;
debug(("Laying domino at i:%d, (%d,%d)\n", i, x, y));
debug(("Laying domino at i:%d, (%d,%d)\n", i, i%state->w, i/state->w));
/* The choice of which type of domino to lay here leads to subtle differences
* in the sorts of boards that get produced. Too much bias towards magnets
@ -2262,7 +2259,7 @@ static void game_print(drawing *dr, game_state *state, int tilesize)
int w = state->w, h = state->h;
int ink = print_mono_colour(dr, 0);
int paper = print_mono_colour(dr, 1);
int x, y, target, count, which, i, j;
int x, y, which, i, j;
/* Ick: fake up `ds->tilesize' for macro expansion purposes */
game_drawstate ads, *ds = &ads;
@ -2277,16 +2274,12 @@ static void game_print(drawing *dr, game_state *state, int tilesize)
draw_sym(dr, ds, state->w, state->h, NEGATIVE, ink);
for (which = POSITIVE, j = 0; j < 2; which = OPPOSITE(which), j++) {
for (i = 0; i < w; i++) {
target = state->common->colcount[i*3+which];
count = count_rowcol(state, i, COLUMN, which);
draw_num_col(dr, ds, COLUMN, which, i, paper, ink,
state->common->colcount[i*3+which]);
state->common->colcount[i*3+which]);
}
for (i = 0; i < h; i++) {
target = state->common->rowcount[i*3+which];
count = count_rowcol(state, i, ROW, which);
draw_num_col(dr, ds, ROW, which, i, paper, ink,
state->common->rowcount[i*3+which]);
state->common->rowcount[i*3+which]);
}
}

View File

@ -2170,7 +2170,7 @@ static int open_square(game_state *state, int x, int y)
static game_state *new_game(midend *me, game_params *params, char *desc)
{
game_state *state = snew(game_state);
int i, wh, x, y, ret, masked;
int i, wh, x, y, masked;
unsigned char *bmp;
state->w = params->w;
@ -2265,7 +2265,7 @@ static game_state *new_game(midend *me, game_params *params, char *desc)
}
if (x >= 0 && y >= 0)
ret = open_square(state, x, y);
open_square(state, x, y);
sfree(bmp);
}

View File

@ -1059,7 +1059,7 @@ static char *interpret_move(game_state *state, game_ui *ui,
game_drawstate *ds, int x, int y, int button)
{
int cx, cy;
int n, dx, dy;
int dx, dy;
char buf[80];
button &= ~MOD_MASK;
@ -1101,7 +1101,6 @@ static char *interpret_move(game_state *state, game_ui *ui,
if (cx == -1) dx = +1;
else if (cx == state->width) dx = -1;
else return NULL;
n = state->width;
dy = 0;
}
else if (cx >= 0 && cx < state->width && cx != state->cx)
@ -1109,7 +1108,6 @@ static char *interpret_move(game_state *state, game_ui *ui,
if (cy == -1) dy = +1;
else if (cy == state->height) dy = -1;
else return NULL;
n = state->height;
dx = 0;
}
else
@ -1585,7 +1583,7 @@ static void draw_arrow_for_cursor(drawing *dr, game_drawstate *ds,
static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
game_state *state, int dir, game_ui *ui, float t, float ft)
{
int x, y, tx, ty, frame;
int x, y, frame;
unsigned char *active;
float xshift = 0.0;
float yshift = 0.0;
@ -1677,7 +1675,6 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
t = ANIM_TIME - t;
}
tx = ty = -1;
if (oldstate && (t < ANIM_TIME)) {
/*
* We're animating a slide, of row/column number

View File

@ -459,7 +459,7 @@ static int tents_solve(int w, int h, const char *grid, int *numbers,
char *soln, struct solver_scratch *sc, int diff)
{
int x, y, d, i, j;
char *mrow, *mrow1, *mrow2, *trow, *trow1, *trow2;
char *mrow, *trow, *trow1, *trow2;
/*
* Set up solver data.
@ -746,8 +746,6 @@ static int tents_solve(int w, int h, const char *grid, int *numbers,
* hasn't been set up yet.
*/
mrow = sc->mrows;
mrow1 = sc->mrows + len;
mrow2 = sc->mrows + 2*len;
trow = sc->trows;
trow1 = sc->trows + len;
trow2 = sc->trows + 2*len;

View File

@ -1225,14 +1225,13 @@ static int check_errors(game_state *state, int *errors)
}
for (i = 0; i < 4*w; i++) {
int start, step, j, k, n, best;
int start, step, j, n, best;
STARTSTEP(start, step, i, w);
if (!clues[i])
continue;
best = n = 0;
k = 0;
for (j = 0; j < w; j++) {
int number = grid[start+j*step];
if (!number)

View File

@ -432,12 +432,11 @@ static char *new_game_desc(game_params *params, random_state *rs,
static char *validate_desc(game_params *params, char *desc)
{
char *p, *err;
char *p;
int w = params->w, h = params->h, wh = w*h;
int i;
p = desc;
err = NULL;
for (i = 0; i < wh; i++) {
if (*p < '0' || *p > '9')

View File

@ -951,7 +951,7 @@ static int gg_best_clue(game_state *state, int *scratch, digit *latin)
{
int ls = state->order * state->order * 5;
int maxposs = 0, minclues = 5, best = -1, i, j;
int nposs, nclues, loc, x, y;
int nposs, nclues, loc;
#ifdef STANDALONE_SOLVER
if (solver_show_working) {
@ -964,7 +964,6 @@ static int gg_best_clue(game_state *state, int *scratch, digit *latin)
if (!gg_place_clue(state, scratch[i], latin, 1)) continue;
loc = scratch[i] / 5;
x = loc % state->order; y = loc / state->order;
for (j = nposs = 0; j < state->order; j++) {
if (state->hints[loc*state->order + j]) nposs++;
}
@ -975,9 +974,11 @@ static int gg_best_clue(game_state *state, int *scratch, digit *latin)
(nposs == maxposs && nclues < minclues)) {
best = i; maxposs = nposs; minclues = nclues;
#ifdef STANDALONE_SOLVER
if (solver_show_working)
if (solver_show_working) {
int x = loc % state->order, y = loc / state->order;
printf("gg_best_clue: b%d (%d,%d) new best [%d poss, %d clues].\n",
best, x+1, y+1, nposs, nclues);
}
#endif
}
}

View File

@ -895,7 +895,7 @@ static char *validate_desc(game_params *params, char *desc)
{
int w = params->w, h = params->h, wh = w*h;
int *active, *link;
int mains = 0, mpos = -1;
int mains = 0;
int i, tx, ty, minmoves;
char *ret;
@ -966,7 +966,6 @@ static char *validate_desc(game_params *params, char *desc)
link[i] = -1;
if (strchr("mM", c) != NULL) {
mains++;
mpos = i;
}
i++;
}
@ -2363,14 +2362,17 @@ int main(int argc, char **argv)
game_state *s;
char *id = NULL, *desc, *err;
int count = FALSE;
int ret, really_verbose = FALSE;
int ret;
int *moves;
while (--argc > 0) {
char *p = *++argv;
/*
if (!strcmp(p, "-v")) {
really_verbose = TRUE;
} else if (!strcmp(p, "-c")) {
verbose = TRUE;
} else
*/
if (!strcmp(p, "-c")) {
count = TRUE;
} else if (*p == '-') {
fprintf(stderr, "%s: unrecognised option `%s'\n", argv[0], p);