~sebsite/generic-tetromino-game

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] Options: Fix going to the next page when there are no useroptions

Lorenz (xha) <me@xha.li>
Details
Message ID
<20230312072225.23532-1-me@xha.li>
DKIM signature
pass
Download raw message
Patch: +7 -4
---
 main.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/main.c b/main.c
index 8f27c46..781fcf8 100644
--- a/main.c
+++ b/main.c
@@ -7791,10 +7791,11 @@ optionsinput(uint8_t inputs)
				|| state.options.pos == 19) {
			if (state.options.page == state.options.userlen / 20 + 1) {
				state.options.page = 0;
			} else {
				draw_options_page();
			} else if (state.options.userlen > 0) {
				++state.options.page;
				draw_options_page();
			}
			draw_options_page();
		} else {
			++state.options.pos;
			optionsupdate();
@@ -7805,8 +7806,10 @@ optionsinput(uint8_t inputs)
		if (state.options.pos == 0) {
			uint8_t pos;
			if (state.options.page == 0) {
				state.options.page = state.options.userlen / 20 + 1;
				pos = MIN(19, state.options.userlen % 20 - 1);
				if (state.options.userlen > 0) {
					state.options.page = state.options.userlen / 20 + 1;
					pos = MIN(19, state.options.userlen % 20 - 1);
				}
			} else {
				--state.options.page;
				pos = state.options.page > 0 ? 19 : OPT_LAST;
-- 
2.38.4
Details
Message ID
<CR4RWLVWPR3W.1EQKIGVADUKQG@notmylaptop>
In-Reply-To
<20230312072225.23532-1-me@xha.li> (view parent)
DKIM signature
pass
Download raw message
On Sun Mar 12, 2023 at 3:22 AM EDT, Lorenz (xha) wrote:
> -			} else {
> +				draw_options_page();
> +			} else if (state.options.userlen > 0) {
>  				++state.options.page;
> +				draw_options_page();
>  			}
> -			draw_options_page();

Why make the change with draw_options_page()? Looks like this could be
simplified by leaving draw_options_page alone, and only changing the
else to the else if.

> @@ -7805,8 +7806,10 @@ optionsinput(uint8_t inputs)
>  		if (state.options.pos == 0) {
>  			uint8_t pos;
>  			if (state.options.page == 0) {
> -				state.options.page = state.options.userlen / 20 + 1;
> -				pos = MIN(19, state.options.userlen % 20 - 1);
> +				if (state.options.userlen > 0) {
> +					state.options.page = state.options.userlen / 20 + 1;
> +					pos = MIN(19, state.options.userlen % 20 - 1);
> +				}
>  			} else {
>  				--state.options.page;
>  				pos = state.options.page > 0 ? 19 : OPT_LAST;

This has undefined behavior: pos is never initialized when both
state.options.page and state.options.userlen are 0.

Also, I think the ideal behavior here is that if there aren't any other
pages, pressing up at the top should set the position to the bottom
rather than just doing nothing.
Reply to thread Export thread (mbox)