diff options
author | Franklin Wei <franklin@rockbox.org> | 2020-06-25 14:44:33 -0400 |
---|---|---|
committer | Franklin Wei <franklin@rockbox.org> | 2020-06-25 18:45:58 +0000 |
commit | 48b0ef1cf22ec37927116ac83ea7c7cfc1f9083e (patch) | |
tree | 148ced6ae04e578abc38a38e92879fa13b97a604 /apps/plugins/puzzles/src/twiddle.c | |
parent | dd3a8e08988308cf88c10a44176d83a8a152ec4a (diff) | |
download | rockbox-48b0ef1cf22ec37927116ac83ea7c7cfc1f9083e.tar.gz rockbox-48b0ef1cf22ec37927116ac83ea7c7cfc1f9083e.zip |
puzzles: resync with upstream
This brings the upstream version to 9aa7b7c (with some of my changes as
well).
Change-Id: I5bf8a3e0b8672d82cb1bf34afc07adbe12a3ac53
Diffstat (limited to 'apps/plugins/puzzles/src/twiddle.c')
-rw-r--r-- | apps/plugins/puzzles/src/twiddle.c | 11 |
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, |