~emersion/mrsh

74081861b03991708c130c09dba6b2a9d9db768e — emersion 3 years ago c7d1e9c
shell: fix process_remove
1 files changed, 7 insertions(+), 3 deletions(-)

M shell/process.c
M shell/process.c => shell/process.c +7 -3
@@ 19,12 19,16 @@ int process_poll(struct process *proc) {
	return WEXITSTATUS(proc->stat);
}

static void array_remove(struct mrsh_array *array, size_t i) {
	memmove(&array->data[i], &array->data[i + 1],
		(array->len - i - 1) * sizeof(void *));
	--array->len;
}

static void process_remove(struct process *proc) {
	for (size_t i = 0; i < running_processes.len; ++i) {
		if (running_processes.data[i] == proc) {
			memmove(&running_processes.data[i], &running_processes.data[i + 1],
				running_processes.len - i - 1);
			--running_processes.len;
			array_remove(&running_processes, i);
			break;
		}
	}