From nobody Fri Nov 22 04:53:06 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 4XvjQq32TVz5dLw0; Fri, 22 Nov 2024 04:53:07 +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 4XvjQq054Kz4t0m; Fri, 22 Nov 2024 04:53:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732251187; 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=TvXX7T5Goir+Zl1TAfjecdXSfbpouajI1FyFwcUb6u0=; b=rGqpwFbdD+P7GphD0lid62ZSu1wdTunDkaCD2+FQIGqBfxx/7j0qhL9BhF+9Ss3WxXcJjK d89uV2bgvmGXqSyprliyYKF2ruj3YSLJMMiGPnx8cJA65p0LtTQ5wN80Qbcuvv2ZCKl67s IT659AfW4k4C7Kca9ErClj87QHrC+1lIMb+10Z9Mqp70xU+eSiMAl1ly64itlDstxgNs5V lmMgcnL+c+5vQM43tKvJjCT2aLDXK/eZfHQCWj2YpCcL86qbyDizsFNbc7zgjrckaVsQL6 VdguGKUBjfk/4mnVhskHYeJu2putW493kT0Jl2Z3eFRynKxM4tqxujFhrqN9Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732251187; 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=TvXX7T5Goir+Zl1TAfjecdXSfbpouajI1FyFwcUb6u0=; b=JbH6JX5i1XTcnIliec4XrCEpp5wCkomwpcYEpLctA3lNpWZ8Gj/UcMyGHpQGHgr/4CuhbG F7baHmKqSnaYj3mK9K7cYgNnmy+T7xbQhfVspt+HBEK/mVxLUvpPEalv+WDagL1CfmFk8L 6itMTGQi8TPYKrFhjcjSj/DBw6SGlp/6t8KYQ9NDeI0GvBgnRy2FlMqsa+iGiDTfDZk3Xt UBmkMAM32Dm0yrcfn/wRZmjjlzBGqarcX5b02tpPOb9YVQU0l1T2u59EziZopLS75X5WcY QHEjmZi+4cLjdnu+4ho2DuclT/Vh/qvSAtk+T67xhdSltw+5PuFvpZbW9u4ZZw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1732251187; a=rsa-sha256; cv=none; b=RXc3ilYULp7TQ+LefUC1oUupqcDAmCkQjb/InCJH7FBLpTgyRbAK6+iouH5EIsHJiGgizK bZkj8vYepZcGq5IjM6LvOyqzShrnH71aFVN5jgDBo1yRULwwUWWS+TgOr1w07jm1ci9K7n t5Xvnovxpj81xSaTkJX3J1ELnZ7nWVZT35BtBH1UrcOQ4erSr0H6JugOmj/6BvTnJ8mLZZ 0GNVT6mLCsVm3x7R3cKq/EHwrpGdEaQ9B6SKfA6GJpyC17Sd0SUUxDmpYpUps/hOKECGR3 voogNei+bJvkJ4bSGUd7Kslbi7F3E7Mc1cg2BoE/yQzVJHgr4tDsxQl5R8eMzQ== 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 4XvjQp6pTTz19HY; Fri, 22 Nov 2024 04:53:06 +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 4AM4r6ag034373; Fri, 22 Nov 2024 04:53:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4AM4r6ft034370; Fri, 22 Nov 2024 04:53:06 GMT (envelope-from git) Date: Fri, 22 Nov 2024 04:53:06 GMT Message-Id: <202411220453.4AM4r6ft034370@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: 3f309e953152 - stable/14 - 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/14 X-Git-Reftype: branch X-Git-Commit: 3f309e9531529aaee3b3da9aaff5582b565c75ac Auto-Submitted: auto-generated The branch stable/14 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=3f309e9531529aaee3b3da9aaff5582b565c75ac commit 3f309e9531529aaee3b3da9aaff5582b565c75ac Author: Martin Cracauer AuthorDate: 2024-11-07 03:40:02 +0000 Commit: Kyle Evans CommitDate: 2024-11-22 04:51:53 +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 }