diff options
author | gabor <gabor@FreeBSD.org> | 2011-04-07 12:52:46 +0000 |
---|---|---|
committer | gabor <gabor@FreeBSD.org> | 2011-04-07 12:52:46 +0000 |
commit | a39cca6aa44fb41dad43abc8314ab193828507dc (patch) | |
tree | 62d588a46a6aa0280cd9afde4e9d1f4c8b773773 /usr.bin/grep | |
parent | d633983d6c998c542faecf7da23b15e641232cf3 (diff) | |
download | FreeBSD-src-a39cca6aa44fb41dad43abc8314ab193828507dc.zip FreeBSD-src-a39cca6aa44fb41dad43abc8314ab193828507dc.tar.gz |
- 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
Diffstat (limited to 'usr.bin/grep')
-rw-r--r-- | usr.bin/grep/fastgrep.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/usr.bin/grep/fastgrep.c b/usr.bin/grep/fastgrep.c index d232ac6..3fa993c 100644 --- a/usr.bin/grep/fastgrep.c +++ b/usr.bin/grep/fastgrep.c @@ -60,8 +60,7 @@ fgrepcomp(fastgrep_t *fg, const char *pat) 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++) { |