diff options
author | pfg <pfg@FreeBSD.org> | 2016-05-09 18:53:46 +0000 |
---|---|---|
committer | pfg <pfg@FreeBSD.org> | 2016-05-09 18:53:46 +0000 |
commit | e1fdf30541d064879f2ef544adb15a04d611d7be (patch) | |
tree | f51259797d3116304f33826d047a7dde5d6f2b6e | |
parent | efb4c021b99888e7ead6bac8a2c4adb3aef8ad02 (diff) | |
download | FreeBSD-src-e1fdf30541d064879f2ef544adb15a04d611d7be.zip FreeBSD-src-e1fdf30541d064879f2ef544adb15a04d611d7be.tar.gz |
Simplify redundant malloc'ing in sed -e.
When encountering an -e argument, sed currently mallocs a string to COPY
the optarg -- with '\n' appended. The appendage does not seem necessary --
indeed, the same call to add_compunit processing the sole command (given
without -e) passes the *argv verbatim: without making a copy, and without
appending newline.
This matches what is done in other BSDs.
Submitted by: Mikhail T.
PR: 195929
MFC after: 2 weeks
-rw-r--r-- | usr.bin/sed/main.c | 7 |
1 files changed, 1 insertions, 6 deletions
diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c index 36a3299..a5ff462 100644 --- a/usr.bin/sed/main.c +++ b/usr.bin/sed/main.c @@ -125,7 +125,6 @@ int main(int argc, char *argv[]) { int c, fflag; - char *temp_arg; (void) setlocale(LC_ALL, ""); @@ -147,11 +146,7 @@ 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"); - add_compunit(CU_STRING, temp_arg); + add_compunit(CU_STRING, optarg); break; case 'f': fflag = 1; |