mirror of
https://github.com/javalsai/lidm.git
synced 2026-02-27 12:00:44 +01:00
fix(launch-state): replace last newline with nullbyte
This commit is contained in:
@@ -21,19 +21,17 @@ int read_launch_state(struct LaunchState* NNULLABLE state) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
size_t num = 0;
|
size_t num = 0;
|
||||||
if (getline(&state->username, &num, state_fd) < 0) goto fail;
|
ssize_t chars = getline(&state->username, &num, state_fd);
|
||||||
// not sure I can actually prove it but ughh, getline < 0 will ensure there's
|
if (chars < 0) goto fail;
|
||||||
// something in the string and then I think strcspn is bounded to the final
|
if (state->username[chars] == '\n') state->username[chars] = 0;
|
||||||
// null byte, so it shouldn't go over
|
|
||||||
// NOLINTNEXTLINE(clang-analyzer-security.ArrayBound)
|
|
||||||
state->username[strcspn(state->username, "\n")] = 0;
|
|
||||||
|
|
||||||
num = 0;
|
num = 0;
|
||||||
if (getline(&state->session_opt, &num, state_fd) < 0) {
|
chars = getline(&state->session_opt, &num, state_fd);
|
||||||
|
if (chars < 0) {
|
||||||
free(state->session_opt);
|
free(state->session_opt);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
state->session_opt[strcspn(state->session_opt, "\n")] = 0;
|
if (state->session_opt[chars] == '\n') state->session_opt[chars] = 0;
|
||||||
|
|
||||||
(void)fclose(state_fd);
|
(void)fclose(state_fd);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user