From nobody Thu Nov 07 03:43:12 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 4XkSb50n4cz5cGy4; Thu, 07 Nov 2024 03:43:13 +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 4XkSb44qxcz4smY; Thu, 7 Nov 2024 03:43:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730950992; 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=IlkZ9Q9iZ2GN95KnHWgxqSqIE5gsvAkClRR+G826FbA=; b=yr7wNVllmU7fc2Irpqhu5mh6R5ZXlBoubU7KiKl8P/azJ4Q6hkuFyI4s/Fiv7go84RkxxT sqcYYASJYu6Q3H5jte0BfXv+fK4Uh6GVRUuOVxcRUs344MQdUs2RsntZCUHq3GgOzbS/BS jXHzQMpRuTBv0WqxhjdPdezXTB+FPbfVwjlj0+ov0feWNRdEhq6ar3ONBFEKtSu/whgrHB HCNs1DOfh1eCLWZhFYRb5EakOjoQ8JDtoHNu3sKd1dz4kvm94AY6XU+ahM2108T+80NHAc b3G7FAW+QSRfpNQW/1QUMC5neRYJRv8Q1fp0+J1SREj1PGiOYbLV/hiAl8Ylww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730950992; 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=IlkZ9Q9iZ2GN95KnHWgxqSqIE5gsvAkClRR+G826FbA=; b=Fq31tExbetHmgxkJUdEY470jX2gUqrkclIi3vDYfBNr1L2LtBR1yRa6t2cPxwuBVaX9QdF 6gu/Yyjq2rlN4iDeqV02nPJ1rvQeM5pKA20dharohwE6Fpvk6TNhSZ1hVlyz1VN72F+97J 16HXCLk6e45xz8KWLVDPF7gb6E1zN8TNwu5oE8ruIg0cu5lupp2Egus+WLUu7het5E8xx0 enufh8Bj32Y0KsOOxBTfHtbQFejUicoGU8rB3A34IKVaKsHGkXD2cijBBqXBCj7z7JWI9I sZyD2tsWZEcNMlYoKtngtmPvqYu1jJWvUpvByEXPo6lUSmRzZm0Yn5ElUoILvw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730950992; a=rsa-sha256; cv=none; b=tByXAL7E2oo9KnDL92ANbrzCqLFNNNqP7KwqInWCDQh2JXSTmHCzvxomtd85DE7ZlXo+MF YA+R2oFk0KxeJ89+Te2hNptO12mpMv5ZCxPF0Kt5BCarzlOGyjKSzsY+mRmn62W5Uw/pdk PWtIH1L9KGrTxSvgnRwzapc4zT2VV6qluKwHimHgVk84q65wXDm/zAQGWfQHP4ouXi8yAT EbZBGIFUfyI88bMj9l7NvuA1ZZqlt2RjT8/KQ7uQBcWw6tHqrlL15iKxOplzAYT8/ait06 JHfD2nXENv55A36JoGRrxAyKwe/oBfU0m8BEVSz2SeKjmXHX6AiJBGBPRLzRjQ== 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 4XkSb44RRWzTQx; Thu, 7 Nov 2024 03:43:12 +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 4A73hCFQ035272; Thu, 7 Nov 2024 03:43:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4A73hC21035269; Thu, 7 Nov 2024 03:43:12 GMT (envelope-from git) Date: Thu, 7 Nov 2024 03:43:12 GMT Message-Id: <202411070343.4A73hC21035269@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 0552fdc62caf - main - 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/main X-Git-Reftype: branch X-Git-Commit: 0552fdc62caf034397ffd5b07dfbad853aef5aa8 Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=0552fdc62caf034397ffd5b07dfbad853aef5aa8 commit 0552fdc62caf034397ffd5b07dfbad853aef5aa8 Author: Martin Cracauer AuthorDate: 2024-11-07 03:40:02 +0000 Commit: Kyle Evans CommitDate: 2024-11-07 03:40:45 +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. Differential Revision: https://reviews.freebsd.org/D47377 --- 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 7cc01eb18147..84e1dfa538e6 100644 --- a/usr.bin/sed/main.c +++ b/usr.bin/sed/main.c @@ -137,10 +137,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': @@ -173,7 +171,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 }