diff options
author | Kjell Wooding <kjell@cvs.openbsd.org> | 2006-11-17 03:24:32 +0000 |
---|---|---|
committer | Kjell Wooding <kjell@cvs.openbsd.org> | 2006-11-17 03:24:32 +0000 |
commit | 8b84f88caa1fada1da2f1f9191cfdc6c24dd831a (patch) | |
tree | c79664c1c4942986eae17b3e90099bd6cf7049ad /usr.bin/mg/search.c | |
parent | ee9ca9123e48641bab7cda4c38302e68ebb4f0e9 (diff) |
fix a segfault on isearch. Using ^W to add more than NPAT chars to the
search pattern had an off-by-one. Fix this and one other irritating behavior
with long search patterns.
Noted (similar diff proposed) and tested by deanna phillips
Diffstat (limited to 'usr.bin/mg/search.c')
-rw-r--r-- | usr.bin/mg/search.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/usr.bin/mg/search.c b/usr.bin/mg/search.c index ef83211a148..b3d18401c9e 100644 --- a/usr.bin/mg/search.c +++ b/usr.bin/mg/search.c @@ -1,4 +1,4 @@ -/* $OpenBSD: search.c,v 1.32 2006/07/25 08:27:09 kjell Exp $ */ +/* $OpenBSD: search.c,v 1.33 2006/11/17 03:24:31 kjell Exp $ */ /* This file is in the public domain. */ @@ -305,9 +305,13 @@ isearch(int dir) while (cbo < llength(clp)) { c = lgetc(clp, cbo++); - if ((!firstc && !isalnum(c)) || pptr == NPAT) + if ((!firstc && !isalnum(c))) break; + if (pptr == NPAT - 1) { + ttbeep(); + break; + } firstc = 0; if (!xcase && ISUPPER(c)) c = TOLOWER(c); @@ -354,12 +358,12 @@ isearch(int dir) pptr = 0; if (pptr == 0) success = TRUE; - pat[pptr++] = c; - if (pptr == NPAT) { - ewprintf("Pattern too long"); - return (FALSE); + if (pptr == NPAT - 1) + ttbeep(); + else { + pat[pptr++] = c; + pat[pptr] = '\0'; } - pat[pptr] = '\0'; is_lpush(); if (success != FALSE) { if (is_find(dir) != FALSE) |