From 01c98acc9b4c00302167d987e61d873d0abe9b30 Mon Sep 17 00:00:00 2001 From: millert Date: Wed, 28 Aug 2024 14:30:26 +0000 Subject: [PATCH] Fix the case where the pattern space is empty but does not start with a NUL character, which might occur after using the D command. From Mohamed Akram --- usr.bin/sed/process.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/usr.bin/sed/process.c b/usr.bin/sed/process.c index c2d78940302..7635f2ffd14 100644 --- a/usr.bin/sed/process.c +++ b/usr.bin/sed/process.c @@ -1,4 +1,4 @@ -/* $OpenBSD: process.c,v 1.37 2024/07/17 20:57:16 millert Exp $ */ +/* $OpenBSD: process.c,v 1.38 2024/08/28 14:30:26 millert Exp $ */ /*- * Copyright (c) 1992 Diomidis Spinellis. @@ -387,14 +387,12 @@ substitute(struct s_command *cp) * and at the end of the line, terminate. */ if (match[0].rm_so == match[0].rm_eo) { - if (*s == '\0' || *s == '\n') - slen = -1; - else - slen--; - if (*s != '\0') { + if (slen > 0) { cspace(&SS, s++, 1, APPEND); + slen--; le++; - } + } else + slen = -1; lastempty = 1; } else lastempty = 0; -- 2.20.1