Skip to content

Commit fae0b0d

Browse files
AlexChenvivier
authored andcommitted
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. Reported-by: Euler Robot <[email protected]> Signed-off-by: Alex Chen <[email protected]> Reviewed-by: Peter Maydell <[email protected]> Message-Id: <[email protected]> Signed-off-by: Laurent Vivier <[email protected]>
1 parent 831aaf2 commit fae0b0d

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

util/qemu-openpty.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,9 @@ static int openpty(int *amaster, int *aslave, char *name,
8080
(termp != NULL && tcgetattr(sfd, termp) < 0))
8181
goto err;
8282

83-
if (amaster)
84-
*amaster = mfd;
85-
if (aslave)
86-
*aslave = sfd;
83+
*amaster = mfd;
84+
*aslave = sfd;
85+
8786
if (winp)
8887
ioctl(sfd, TIOCSWINSZ, winp);
8988

0 commit comments

Comments
 (0)