Date: Mon, 9 May 2016 18:53:46 +0000 (UTC) From: "Pedro F. Giffuni" <pfg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r299279 - head/usr.bin/sed Message-ID: <201605091853.u49Irk8s084319@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pfg Date: Mon May 9 18:53:46 2016 New Revision: 299279 URL: https://svnweb.freebsd.org/changeset/base/299279 Log: 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 Modified: head/usr.bin/sed/main.c Modified: head/usr.bin/sed/main.c ============================================================================== --- head/usr.bin/sed/main.c Mon May 9 17:19:17 2016 (r299278) +++ head/usr.bin/sed/main.c Mon May 9 18:53:46 2016 (r299279) @@ -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;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605091853.u49Irk8s084319>