From 9874023096b1940ef3df0756a0ec81d5d57e09c2 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Sun, 20 Jun 2021 13:16:29 +0200 Subject: Clipboard.c: check for invalid index We only need to check this in nxagentHandleSelectionClearFromXServerByIndex, so we can simplify nxagentHandleSelectionClearFromXServerByAtom. --- nx-X11/programs/Xserver/hw/nxagent/Clipboard.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c index 4a0bf9cb5..3b08c1133 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Clipboard.c @@ -882,6 +882,14 @@ void nxagentHandleSelectionClearFromXServerByIndex(int index) fprintf(stderr, "%s: SelectionClear event for selection index [%u].\n", __func__, index); #endif + if (index == -1) + { + #ifdef DEBUG + fprintf(stderr, "%s: ignoring index -1 - doing nothing.\n", __func__); + #endif + return; + } + if (!agentClipboardInitialized) { #ifdef DEBUG @@ -931,11 +939,7 @@ void nxagentHandleSelectionClearFromXServerByAtom(XlibAtom sel) fprintf(stderr, "---------\n%s: SelectionClear event for remote selection atom [%lu][%s].\n", __func__, sel, NameForRemoteAtom(sel)); #endif - int index = nxagentFindRemoteSelectionIndex(sel); - if (index != -1) - { - nxagentHandleSelectionClearFromXServerByIndex(index); - } + nxagentHandleSelectionClearFromXServerByIndex(nxagentFindRemoteSelectionIndex(sel)); } void nxagentHandleSelectionClearFromXServer(XEvent *X) -- cgit v1.2.3