From nobody Tue Jan 14 14:43:48 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YXX1x3Plzz5km50; Tue, 14 Jan 2025 14:43:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YXX1x0lYbz3grM; Tue, 14 Jan 2025 14:43:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736865829; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gqTW6Un84ctWBIOefR6eIGOiDXci4CdJHH51xkteYho=; b=xDwsM5RlvjyZPu/hktEES9NWDLnXMD1+616u8zpFwMQ5SHyNiX9MYRxptfJo/YeFKYXKCS OgS/trobcjvaXkn+SOLn1eyNeVM6ihENFI37KPqt+2wcanUz4h4F6yyqe8xUSvtXY3jzC3 h1WOq3p/sbZtNvHXIz+1A11Wj3dxW6RkJqw0a1BCHvJRccT1hw5PxKMSylexHOdo+02aCZ tTB9AwiuFZrPTYxL25Vbkk43xopmto5X6ZGDctv/phShmC9Ii1ukv3W4pQQgLBSdS6Yzb+ R/YL8UpieAePTYb/bxyAxdOrFJUu169Tewj8ZXrAoOZbhEJftn+hWXOzIVgT7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736865829; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gqTW6Un84ctWBIOefR6eIGOiDXci4CdJHH51xkteYho=; b=TfvzBNuX4UaLMPOjmrahnDT4D6WEk9TWsHxxWrJLbU9473iLYfI6h7LToD6kxVcYDq6ppD GIMNF5Gq6j0PTtLZOUNhJxcgO8H7ahtuZIDHMZ0TXkMlR4qKhd6MQS5CLT1JVAEAx32ogH PSbqSc1JM2PXIM7+3z84ZOrPNMcDQRFC0Lw0AF7YHr4VKiygHvld2YOmlY2c+nEmtqTThz G+Udx1/IPUS/qUjMXL0vO7c5jAcomDULjKlyDH5jCQpyix0kRKDVhA9swVqe+0xvZK7OIk f0G/vsKecUQ5G0YZRb6KobmAHqyL15ystvU8C3HGDajQ6ufMHogM31lSRcJh9w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1736865829; a=rsa-sha256; cv=none; b=qFIOnsZ5LsjAzKGM/pnNymnv+AKi0XtbHqtt848BswxwgWh95phzS8doIGF6Zb8AhXDzpQ xnXut9S5uqb26WQy+Rd8NTuBAt29Z1oeEqwKPoSrtzNT+tWDMg5cprmI9KPq5Qa1gmXC4I 6ib3uSY2U82R9uCnv+JRW8S6/9v54Q7slRJOs3jyiLed91S0sZPpSDTJyzpwrxJyjopCvz thXbGrBetoLDf0BlKmVfuUa085h3L1NFNlDrdlHGgEK7vfZIjQNeUvk5vxmo5qFdrxnem7 Ha4JaDqJfjJkVgEyrWUIR1Y2N6cUAMUsZOM3HbtkPTtanjMGxCP7ZsKE2QtOiw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YXX1x0LfJz1Jgl; Tue, 14 Jan 2025 14:43:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 50EEhmCA014784; Tue, 14 Jan 2025 14:43:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50EEhmoO014781; Tue, 14 Jan 2025 14:43:48 GMT (envelope-from git) Date: Tue, 14 Jan 2025 14:43:48 GMT Message-Id: <202501141443.50EEhmoO014781@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 91af1b8001d3 - stable/13 - sed: Fix handling of an empty pattern space List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 91af1b8001d34a1563d861f1da81deaa121adca8 Auto-Submitted: auto-generated The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=91af1b8001d34a1563d861f1da81deaa121adca8 commit 91af1b8001d34a1563d861f1da81deaa121adca8 Author: Mohamed Akram AuthorDate: 2024-12-23 19:06:09 +0000 Commit: Mark Johnston CommitDate: 2025-01-14 14:43:05 +0000 sed: Fix handling of an empty pattern space Add a regression test. PR: 271791 Obtained from: OpenBSD (1.38 millert) MFC after: 2 weeks (cherry picked from commit 5982237f1e5a30b6b7d67b307b4d3685b00718bf) --- usr.bin/sed/process.c | 10 ++++------ usr.bin/sed/tests/sed2_test.sh | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/usr.bin/sed/process.c b/usr.bin/sed/process.c index 3d88096ffb77..945db462a601 100644 --- a/usr.bin/sed/process.c +++ b/usr.bin/sed/process.c @@ -439,14 +439,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; diff --git a/usr.bin/sed/tests/sed2_test.sh b/usr.bin/sed/tests/sed2_test.sh index f50619612561..0b849b1ea132 100755 --- a/usr.bin/sed/tests/sed2_test.sh +++ b/usr.bin/sed/tests/sed2_test.sh @@ -159,6 +159,19 @@ minus_e_body() atf_check -o 'inline:--\nab\n' sed $'1 i\\\n--' a } +atf_test_case command_D +command_D_head() +{ + atf_set "descr" "Test handling of an empty pattern space" +} +command_D_body() +{ + printf "hello\n\nworld\n" > a + + atf_check -o file:a sed -e 's/^//;P;D' a + atf_check -o file:a sed -e 's/^//;$!N;P;D' a +} + atf_init_test_cases() { atf_add_test_case inplace_command_q @@ -169,4 +182,5 @@ atf_init_test_cases() atf_add_test_case hex_subst atf_add_test_case bracket_y atf_add_test_case minus_e + atf_add_test_case command_D }