From d37f9f31176ab94304fcc72b4aef507e2147005a Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Wed, 26 Oct 2016 10:39:37 +0200 Subject: Reconnect.c: simplify code by using strndup Also abort reconnect on strndup failure. --- nx-X11/programs/Xserver/hw/nxagent/Reconnect.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'nx-X11/programs/Xserver/hw/nxagent') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Reconnect.c b/nx-X11/programs/Xserver/hw/nxagent/Reconnect.c index c20386ea1..65e2ae795 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Reconnect.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Reconnect.c @@ -438,22 +438,14 @@ Bool nxagentReconnectSession(void) if (nxagentKeyboard != NULL) { - int size; - - size = strlen(nxagentKeyboard); - - if ((nxagentOldKeyboard = malloc(size + 1)) != NULL) + nxagentOldKeyboard = strndup(nxagentKeyboard, strlen(nxagentKeyboard)); + if (nxagentOldKeyboard == NULL) { - strncpy(nxagentOldKeyboard, nxagentKeyboard, size); - - nxagentOldKeyboard[size] = '\0'; + /* 0 means reconnection failed */ + return 0; } - } - if (nxagentKeyboard) - { free(nxagentKeyboard); - nxagentKeyboard = NULL; } -- cgit v1.2.3