From 3b31aeaae387d473effbf6e507b5c1e76aec1b0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Wed, 28 Feb 2024 13:33:12 +0100 Subject: [PATCH] virsh: remove trailing whitespace even when editing the description MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When editing the title of a domain or network via the `desc` or `net-desc` commands, we strip the final newline that is added by some editors. Do the same when editing the description as well. Signed-off-by: Ján Tomko Reviewed-by: Michal Privoznik --- tools/virsh-domain.c | 5 ++--- tools/virsh-network.c | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index d3e28f38f4..2e9510983c 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -8525,10 +8525,9 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) return false; /* strip a possible newline at the end of file; some - * editors enforce a newline, this makes editing the title + * editors enforce a newline, this makes editing * more convenient */ - if (title && - (tmpstr = strrchr(desc_edited, '\n')) && + if ((tmpstr = strrchr(desc_edited, '\n')) && *(tmpstr+1) == '\0') *tmpstr = '\0'; diff --git a/tools/virsh-network.c b/tools/virsh-network.c index 68c7543863..c676fc603c 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -481,8 +481,7 @@ cmdNetworkDesc(vshControl *ctl, const vshCmd *cmd) /* strip a possible newline at the end of file; some * editors enforce a newline, this makes editing the title * more convenient */ - if (title && - (tmpstr = strrchr(desc_edited, '\n')) && + if ((tmpstr = strrchr(desc_edited, '\n')) && *(tmpstr+1) == '\0') *tmpstr = '\0';