summaryrefslogtreecommitdiff
path: root/apps/plugins/puzzles/src/twiddle.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/puzzles/src/twiddle.c')
-rw-r--r--apps/plugins/puzzles/src/twiddle.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/apps/plugins/puzzles/src/twiddle.c b/apps/plugins/puzzles/src/twiddle.c
index 1d91559e37..5f2ea02e6f 100644
--- a/apps/plugins/puzzles/src/twiddle.c
+++ b/apps/plugins/puzzles/src/twiddle.c
@@ -552,6 +552,12 @@ static char *game_text_format(const game_state *state)
552 int i, x, y, col, maxlen; 552 int i, x, y, col, maxlen;
553 bool o = state->orientable; 553 bool o = state->orientable;
554 554
555 /* Pedantic check: ensure buf is large enough to format an int in
556 * decimal, using the bound log10(2) < 1/3. (Obviously in practice
557 * int is not going to be larger than even 32 bits any time soon,
558 * but.) */
559 assert(sizeof(buf) >= 1 + sizeof(int) * CHAR_BIT/3);
560
555 /* 561 /*
556 * First work out how many characters we need to display each 562 * First work out how many characters we need to display each
557 * number. We're pretty flexible on grid contents here, so we 563 * number. We're pretty flexible on grid contents here, so we
@@ -563,6 +569,11 @@ static char *game_text_format(const game_state *state)
563 if (col < x) col = x; 569 if (col < x) col = x;
564 } 570 }
565 571
572 /* Reassure sprintf-checking compilers like gcc that the field
573 * width we've just computed is not now excessive */
574 if (col >= sizeof(buf))
575 col = sizeof(buf)-1;
576
566 /* 577 /*
567 * Now we know the exact total size of the grid we're going to 578 * Now we know the exact total size of the grid we're going to
568 * produce: it's got h rows, each containing w lots of col+o, 579 * produce: it's got h rows, each containing w lots of col+o,