util: Remove redundant checks in the openpty()
PATCH v2 1/1 util: Remove redundant checks in the openpty()
As we can see from the following function call stack, amaster and aslave can not be NULL: char_pty_open() -> qemu_openpty_raw() -> openpty(). In addition, according to the API specification for openpty():
https://www.gnu.org/software/libc/manual/html_node/Pseudo_002dTerminal-Pairs.html,
the arguments name, termp and winp can all be NULL, but arguments amaster or aslave can not be NULL.
Finally, amaster and aslave has been dereferenced at the beginning of the openpty(). So the checks on amaster and aslave in the openpty() are redundant. Remove them.
--- util/qemu-openpty.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
util/qemu-openpty.c +3 -4
@@ -80,10 +80,9 @@ static int openpty(int *amaster, int *aslave, char *name, (termp != NULL && tcgetattr(sfd, termp) < 0)) goto err; -if (amaster) - *amaster = mfd; -if (aslave) - *aslave = sfd; + *amaster = mfd; + *aslave = sfd; +if (winp)ioctl (sfd,TIOCSWINSZ , winp);
Signature · 1 line
2.19.1
Hi all,
This patch has been reviewed by Peter. who can help merge it?
Thanks,
Alex
Quoted 34 lines · AlexChen
As we can see from the following function call stack, amaster and aslave can not be NULL:
char_pty_open()->qemu_openpty_raw()->openpty(). In addition, according to the API specification foropenpty():
https://www.gnu.org/software/libc/manual/html_node/Pseudo_002dTerminal-Pairs.html,
the arguments name, termp and winp can all be NULL, but arguments amaster or aslave can not be NULL.
Finally, amaster and aslave has been dereferenced at the beginning of theopenpty(). So the checks on amaster and aslave in theopenpty()are redundant. Remove them.Reported-by Euler Robot <[email protected]>Signed-off-by Alex Chen <[email protected]>Reviewed-by Peter Maydell <[email protected]>--- util/qemu-openpty.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)util/qemu-openpty.c +3
-4@@ -80,10 +80,9 @@ static int openpty(int *amaster, int *aslave, char *name, (termp != NULL && tcgetattr(sfd, termp) < 0)) goto err; -if (amaster) - *amaster = mfd; -if (aslave) - *aslave = sfd; + *amaster = mfd; + *aslave = sfd; +if (winp)ioctl (sfd,TIOCSWINSZ , winp);
Laurent Vivier
AppliedLe 14/09/2021 à 09:43, Alex Chen a écrit :
Quoted 32 lines
Hi all,
This patch has been reviewed by Peter. who can help merge it?
Thanks,
AlexQuoted 24 lines · AlexChen
As we can see from the following function call stack, amaster and aslave can not be NULL:
char_pty_open()->qemu_openpty_raw()->openpty(). In addition, according to the API specification foropenpty():
https://www.gnu.org/software/libc/manual/html_node/Pseudo_002dTerminal-Pairs.html,
the arguments name, termp and winp can all be NULL, but arguments amaster or aslave can not be NULL.
Finally, amaster and aslave has been dereferenced at the beginning of theopenpty(). So the checks on amaster and aslave in theopenpty()are redundant. Remove them.Reported-by Euler Robot <[email protected]>Signed-off-by Alex Chen <[email protected]>Reviewed-by Peter Maydell <[email protected]>--- util/qemu-openpty.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)util/qemu-openpty.c +0
-0@@ -80,10 +80,9 @@ static int openpty(int *amaster, int *aslave, char *name, (termp != NULL && tcgetattr(sfd, termp) < 0)) goto err;
Quoted 12 lines
util/qemu-openpty.c static int openpty(int *amaster, int *aslave, char *name, · line 88
Quoted 10 lines
util/qemu-openpty.c +3
-4-if (amaster) - *amaster = mfd; -if (aslave) - *aslave = sfd; + *amaster = mfd; + *aslave = sfd; +if (winp)ioctl (sfd,TIOCSWINSZ , winp);
Applied to my trivial-patches branch.
Thanks,
Laurent