From dd6760127c71c58c46762d2674198b618f42639b Mon Sep 17 00:00:00 2001 From: grialion <48643945+grialion@users.noreply.github.com> Date: Sun, 8 Feb 2026 17:39:09 +0100 Subject: [PATCH] fix: launch state off by one bug (#116) Previously it couldn't find the currect user/session because the last newline character was present in the field --- src/launch_state.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/launch_state.c b/src/launch_state.c index 76c4c92..db33366 100644 --- a/src/launch_state.c +++ b/src/launch_state.c @@ -22,16 +22,16 @@ int read_launch_state(struct LaunchState* NNULLABLE state) { size_t num = 0; ssize_t chars = getline(&state->username, &num, state_fd); - if (chars < 0) goto fail; - if (state->username[chars] == '\n') state->username[chars] = 0; + if (chars <= 0) goto fail; + if (state->username[chars - 1] == '\n') state->username[chars - 1] = 0; num = 0; chars = getline(&state->session_opt, &num, state_fd); - if (chars < 0) { + if (chars <= 0) { free(state->session_opt); goto fail; } - if (state->session_opt[chars] == '\n') state->session_opt[chars] = 0; + if (state->session_opt[chars - 1] == '\n') state->session_opt[chars - 1] = 0; (void)fclose(state_fd); return 0;