From a0f730ed9b253d8d9f49e7a339955e4e146f8745 Mon Sep 17 00:00:00 2001 From: kcwu Date: Wed, 1 Jul 2009 07:13:14 +0000 Subject: fix bug: search in edit.c * access violation if search forward and cursor at end of line * currline will become NULL if search backward and cursor at the first keyword git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4722 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/edit.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'mbbsd') diff --git a/mbbsd/edit.c b/mbbsd/edit.c index 640ae75c..e0bc0c9a 100644 --- a/mbbsd/edit.c +++ b/mbbsd/edit.c @@ -2994,20 +2994,28 @@ search_str(int mode) textline_t *p; char *pos = NULL; int lino; + bool found = false; if (mode >= 0) { - for (lino = curr_buf->currln, p = curr_buf->currline; p; p = p->next, lino++) - if ((pos = (*curr_buf->substr_fp)(p->data + (lino == curr_buf->currln ? curr_buf->currpnt + 1 : 0), - str)) && (lino != curr_buf->currln || - pos - p->data != curr_buf->currpnt)) + for (lino = curr_buf->currln, p = curr_buf->currline; p; p = p->next, lino++) { + int offset = (lino == curr_buf->currln ? MIN(curr_buf->currpnt + 1, curr_buf->currline->len) : 0); + pos = (*curr_buf->substr_fp)(p->data + offset, str); + if (pos) { + found = true; break; + } + } } else { - for (lino = curr_buf->currln, p = curr_buf->currline; p; p = p->prev, lino--) - if ((pos = (*curr_buf->substr_fp)(p->data, str)) && - (lino != curr_buf->currln || pos - p->data != curr_buf->currpnt)) + for (lino = curr_buf->currln, p = curr_buf->currline; p; p = p->prev, lino--) { + pos = (*curr_buf->substr_fp)(p->data, str); + if (pos && + (lino != curr_buf->currln || pos - p->data < curr_buf->currpnt)) { + found = true; break; + } + } } - if (pos) { + if (found) { /* move window */ curr_buf->currline = p; curr_buf->currln = lino; -- cgit v1.2.3