diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c --- a/usr.bin/sed/main.c +++ b/usr.bin/sed/main.c @@ -137,10 +137,8 @@ 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 @@ /* 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 --- a/usr.bin/sed/tests/sed2_test.sh +++ b/usr.bin/sed/tests/sed2_test.sh @@ -147,6 +147,18 @@ 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_add_test_case commands_on_stdin atf_add_test_case hex_subst atf_add_test_case bracket_y + atf_add_test_case minus_e }