From nobody Fri Nov 22 04:53:51 2024 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 4XvjRh0Kxxz5dLLX; Fri, 22 Nov 2024 04:53:52 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XvjRg6ngXz4vKb; Fri, 22 Nov 2024 04:53:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732251232; 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=fToGjxDi+w2CCSvME5lIPe2aKAIzUOEjcQxen7kKE+I=; b=U5ObG0D89dD4wVLqUTfDNQRUfwHcqcrxYgzoc0mn3xWYjm/cu8YeBEmvGx/H+l4/kW0u3R Jj7/AHybX2vcZ4byXS3w5gUbqJF47Acllmm8ibU2FhfkadmPS/+VDPuXTSxoO8L4jOtZr3 WVhgHihgqD7476YTnHCJZO+dX5pzOE0C9GabSS1VPV0QJZSB7FTYHpZsCRZILjw/oVfx6e rG8ESG7QyLXCJ8oa3NuhjgtVIE2YgRuQOa1rYh7byt7auhMH8F32mnVrIO/mWboqR1Z/5Z jPVV85rG08CjN5G4stUndwHDXe8kXJhb7fPOpNEzNX4Rw+/qCoqt3022flsLTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732251232; 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=fToGjxDi+w2CCSvME5lIPe2aKAIzUOEjcQxen7kKE+I=; b=WkjTgGdK87D+sgVB70VvhBgXNaVS/v82n6U1VI0P/xtjqmsdmZPU/f+KFY7w5aUAG0kCnD LekNWF48UnM97BMKqZdRwfMVvJhQA2poGodaRq/2F4SzK+xBKsma18toRUMXj5ZV8qyM2p 8oduXrkKJvf6kfJtYoGQE5MOIK2mgbqkNxPs9wPR0DAt/0Ukz4S5pQNsmmvRYa0RiYA/v9 jefamEbgr9vfX+ES0ekxHDdWB9CsqqDEqy//Bv+vTNRDn1ZJGMFe9vDM5lLuoIsvu4amxO hUui2UW1L/i/6zANnSRTJcJ74IGNh6W7xg4IVSziuzOwOx3WLFgH6HZ9N1/gSg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1732251232; a=rsa-sha256; cv=none; b=HrOtaDG1tHip9b/2SlXVuKhSTnfAOmFpl/xW2o2EQhVMOXojpOb1r9qAIvqr6/SapBwMxc b3hyevYqIohiSmcgMckETGmyGu6zF+Qcahfzjnsx8Log7uGTkrjMxFP5llRH85upPqiVbA d1G6chSSLIHFe/OJANdAHXSrsfuuYDog3IcrfksuzY5DVJ3IhJzESAomSx+EOnOZhpe3bu d7qP+9SdMSqZpjjJX+hpW87UeVxapxXrPwf6bU9jnuDVyUiKYC4qaruLTxdmo3PnYfuabL 6EWM3uyiWwZWQxC7fULxnQFRx6ds2GE3gTLavQYy3+1iILV0+cOxvfNDoo7F/w== 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 4XvjRg6P4Rz19Hb; Fri, 22 Nov 2024 04:53:51 +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 4AM4rplE034956; Fri, 22 Nov 2024 04:53:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4AM4rpeu034953; Fri, 22 Nov 2024 04:53:51 GMT (envelope-from git) Date: Fri, 22 Nov 2024 04:53:51 GMT Message-Id: <202411220453.4AM4rpeu034953@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: 4e609121a764 - stable/13 - sed: fix commandline-given expression when -e is not used 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: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 4e609121a764b103dd2d07630441d1c4cd76bbdd Auto-Submitted: auto-generated The branch stable/13 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=4e609121a764b103dd2d07630441d1c4cd76bbdd commit 4e609121a764b103dd2d07630441d1c4cd76bbdd Author: Martin Cracauer AuthorDate: 2024-11-07 03:40:02 +0000 Commit: Kyle Evans CommitDate: 2024-11-22 04:53:43 +0000 sed: fix commandline-given expression when -e is not used Make explicit sed commands (first on commandline) behave the same as those given with -e. Without this patch the following two commands behave differently, the second one being wrong: echo ab | sed -e $'1 i\\\n--' echo ab | sed $'1 i\\\n--' Reviewed by: 0mp, des, kevans Sponsored by: Klara, Inc. (cherry picked from commit 0552fdc62caf034397ffd5b07dfbad853aef5aa8) --- usr.bin/sed/main.c | 10 +++++----- usr.bin/sed/tests/sed2_test.sh | 13 +++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c index efa28b5e7239..1632b823cc69 100644 --- a/usr.bin/sed/main.c +++ b/usr.bin/sed/main.c @@ -148,10 +148,8 @@ main(int argc, char *argv[]) break; case 'e': eflag = 1; - if ((temp_arg = malloc(strlen(optarg) + 2)) == NULL) - err(1, "malloc"); - strcpy(temp_arg, optarg); - strcat(temp_arg, "\n"); + if (asprintf(&temp_arg, "%s\n", optarg) == -1) + err(1, "asprintf"); add_compunit(CU_STRING, temp_arg); break; case 'f': @@ -184,7 +182,9 @@ main(int argc, char *argv[]) /* First usage case; script is the first arg */ if (!eflag && !fflag && *argv) { - add_compunit(CU_STRING, *argv); + if (asprintf(&temp_arg, "%s\n", *argv) == -1) + err(1, "asprintf"); + add_compunit(CU_STRING, temp_arg); argv++; } diff --git a/usr.bin/sed/tests/sed2_test.sh b/usr.bin/sed/tests/sed2_test.sh index a7408b2560a7..f50619612561 100755 --- a/usr.bin/sed/tests/sed2_test.sh +++ b/usr.bin/sed/tests/sed2_test.sh @@ -147,6 +147,18 @@ bracket_y_body() echo 'bra[ke]' | sed 'y[\[][ct[' } +atf_test_case minus_e +minus_e_head() +{ + atf_set "descr" "Verify that -e and implicit arg do the same thing" +} +minus_e_body() +{ + printf "ab\n" > a + atf_check -o 'inline:--\nab\n' sed -e $'1 i\\\n--' a + atf_check -o 'inline:--\nab\n' sed $'1 i\\\n--' a +} + atf_init_test_cases() { atf_add_test_case inplace_command_q @@ -156,4 +168,5 @@ atf_init_test_cases() atf_add_test_case commands_on_stdin atf_add_test_case hex_subst atf_add_test_case bracket_y + atf_add_test_case minus_e }