From 838d28ab5d5a3c9177e43e66df088f70cc243303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Courr=C3=A8ges-Anglas?= Date: Mon, 3 Mar 2014 14:37:36 +0100 Subject: Fix cmd_getsel when there is no X selection * instead of feeding stdio a NULL string and invoking undefined behavior, return a failure --- src/actions.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/actions.c b/src/actions.c index 3b2692e..7e4fdc3 100644 --- a/src/actions.c +++ b/src/actions.c @@ -5962,11 +5962,17 @@ cmd_putsel (int interactive UNUSED, struct cmdarg **args) cmdret * cmd_getsel (int interactive UNUSED, struct cmdarg **args UNUSED) { - char *sel = get_selection(); + char *sel; cmdret *ret; - ret = cmdret_new (RET_SUCCESS, "%s", sel); - free (sel); - return ret; + sel = get_selection(); + if (sel != NULL) + { + ret = cmdret_new (RET_SUCCESS, "%s", sel); + free (sel); + return ret; + } + else + return cmdret_new (RET_FAILURE, "getsel: no X11 selection"); } /* This is a command that restores old commands that have been -- cgit v1.2.3