Skip to content
Browse files

Check length before checking index of len - 1.

OK moritz@.
  • Loading branch information...
1 parent 77fd982 commit 4741299ea285b765a37d4691b6ee5f8e9b83d933 Ray Lai committed with Nov 2, 2006
Showing with 2 additions and 2 deletions.
  1. +2 −2 grep.c
View
4 grep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: grep.c,v 1.35 2006/03/07 20:59:56 otto Exp $ */
+/* $OpenBSD: grep.c,v 1.36 2006/09/26 15:55:17 jaredy 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) {

0 comments on commit 4741299

Please sign in to comment.
Something went wrong with that request. Please try again.