From 123589d4be20f28dab8bc25fe65b7492ba34cf1b Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Thu, 7 May 2026 19:20:19 +0100 Subject: [PATCH] Fix segfault when both `-z` and `--trim` are used. Fixes #53. --- xsel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xsel.c b/xsel.c index 0dd9bd4..5c1b57e 100644 --- a/xsel.c +++ b/xsel.c @@ -2344,7 +2344,7 @@ main(int argc, char *argv[]) if(trim_trailing_newline) { unsigned int sel_len = xs_strlen(new_sel); - if (new_sel[sel_len - 1 ] == '\n') { + if (sel_len && new_sel[sel_len - 1 ] == '\n') { new_sel[sel_len - 1] = '\0'; } }