diff options
author | Ray Lai <ray@cvs.openbsd.org> | 2006-11-02 18:00:04 +0000 |
---|---|---|
committer | Ray Lai <ray@cvs.openbsd.org> | 2006-11-02 18:00:04 +0000 |
commit | 13281731239c50b4d7499ae5fe1fad87bc286403 (patch) | |
tree | 70e63d915ae064dca09e8e0d5093b82372a22d58 /usr.bin | |
parent | 02ee09281c8494ce23b0961515d79926afb2f24a (diff) |
Check length before checking index of len - 1.
OK moritz@.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/grep/grep.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c index 6b84eae8518..a8a8618b8c4 100644 --- a/usr.bin/grep/grep.c +++ b/usr.bin/grep/grep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grep.c,v 1.36 2006/09/26 15:55:17 jaredy Exp $ */ +/* $OpenBSD: grep.c,v 1.37 2006/11/02 18:00:03 ray Exp $ */ /*- * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav @@ -176,7 +176,7 @@ add_pattern(char *pat, size_t len) pattern_sz *= 2; pattern = grep_realloc(pattern, ++pattern_sz * sizeof(*pattern)); } - if (pat[len - 1] == '\n') + if (len > 0 && pat[len - 1] == '\n') --len; /* pat may not be NUL-terminated */ if (wflag && !Fflag) { |