From owner-svn-src-all@FreeBSD.ORG Thu Apr 7 12:52:47 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1F37E106564A; Thu, 7 Apr 2011 12:52:47 +0000 (UTC) (envelope-from gabor@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 0FF5B8FC0C; Thu, 7 Apr 2011 12:52:47 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p37CqkVW041025; Thu, 7 Apr 2011 12:52:46 GMT (envelope-from gabor@svn.freebsd.org) Received: (from gabor@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p37CqkN0041023; Thu, 7 Apr 2011 12:52:46 GMT (envelope-from gabor@svn.freebsd.org) Message-Id: <201104071252.p37CqkN0041023@svn.freebsd.org> From: Gabor Kovesdan Date: Thu, 7 Apr 2011 12:52:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r220420 - head/usr.bin/grep X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Apr 2011 12:52:47 -0000 Author: gabor Date: Thu Apr 7 12:52:46 2011 New Revision: 220420 URL: http://svn.freebsd.org/changeset/base/220420 Log: - Replace some strcpy()-family functions with memcpy() ones. It has been discussed earlier that the extra safeness is not required in these cases and we can avoid the overhead by using the more general memory copy functions. Approved by: delphij (mentor) Obtained from: The NetBSD Project Modified: head/usr.bin/grep/fastgrep.c Modified: head/usr.bin/grep/fastgrep.c ============================================================================== --- head/usr.bin/grep/fastgrep.c Thu Apr 7 11:47:27 2011 (r220419) +++ head/usr.bin/grep/fastgrep.c Thu Apr 7 12:52:46 2011 (r220420) @@ -60,8 +60,7 @@ fgrepcomp(fastgrep_t *fg, const char *pa fg->eol = false; fg->reversed = false; - fg->pattern = grep_malloc(strlen(pat) + 1); - strcpy(fg->pattern, pat); + fg->pattern = (unsigned char *)grep_strdup(pat); /* Preprocess pattern. */ for (i = 0; i <= UCHAR_MAX; i++) @@ -106,9 +105,10 @@ fastcomp(fastgrep_t *fg, const char *pat } if (fg->len >= 14 && - strncmp(pat + (fg->bol ? 1 : 0), "[[:<:]]", 7) == 0 && - strncmp(pat + (fg->bol ? 1 : 0) + fg->len - 7, "[[:>:]]", 7) == 0) { + memcmp(pat, "[[:<:]]", 7) == 0 && + memcmp(pat + fg->len - 7, "[[:>:]]", 7) == 0) { fg->len -= 14; + pat += 7; /* Word boundary is handled separately in util.c */ wflag = true; } @@ -119,7 +119,8 @@ fastcomp(fastgrep_t *fg, const char *pat * string respectively. */ fg->pattern = grep_malloc(fg->len + 1); - strlcpy(fg->pattern, pat + (bol ? 1 : 0) + wflag, fg->len + 1); + memcpy(fg->pattern, pat, fg->len); + fg->pattern[fg->len] = '\0'; /* Look for ways to cheat...er...avoid the full regex engine. */ for (i = 0; i < fg->len; i++) {