mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
Fixed how the original TTY state is preserved
In find_tty_state(), we changed how we expand fd_orig as an original pre-modified copy of fd_setup. We realloc the fd_orig array and copy the fd_setup into it first, before touching the fd_setup array.
This commit is contained in:
17
lib_calc.c
17
lib_calc.c
@@ -796,6 +796,15 @@ find_tty_state(int fd)
|
||||
/*
|
||||
* no empty slots exist, realloc another slot
|
||||
*/
|
||||
/* expand fd_orig as an original pre-modified copy of fd_setup */
|
||||
new_fd_orig = (ttystruct *)realloc(fd_orig, sizeof(fd_orig[0]) *
|
||||
(fd_setup_len+1));
|
||||
if (new_fd_orig == NULL) {
|
||||
return -1;
|
||||
}
|
||||
fd_orig = new_fd_orig;
|
||||
memcpy(fd_orig, fd_setup, sizeof(fd_orig[0]) * (fd_setup_len+1));
|
||||
|
||||
/* expand fd_setup */
|
||||
new_fd_setup = (int *)realloc(fd_setup, sizeof(fd_setup[0]) *
|
||||
(fd_setup_len+1));
|
||||
@@ -805,14 +814,6 @@ find_tty_state(int fd)
|
||||
fd_setup = new_fd_setup;
|
||||
new_fd_setup[fd_setup_len] = -1;
|
||||
|
||||
/* expand fd_orig */
|
||||
new_fd_orig = (ttystruct *)realloc(fd_orig, sizeof(fd_orig[0]) *
|
||||
(fd_setup_len+1));
|
||||
if (new_fd_orig == NULL) {
|
||||
return -1;
|
||||
}
|
||||
fd_orig = new_fd_orig;
|
||||
|
||||
/* expand fd_cur */
|
||||
new_fd_cur = (ttystruct *)realloc(fd_cur, sizeof(fd_cur[0]) *
|
||||
(fd_setup_len+1));
|
||||
|
Reference in New Issue
Block a user