diff options
author | kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2009-07-01 15:13:14 +0800 |
---|---|---|
committer | kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2009-07-01 15:13:14 +0800 |
commit | a0f730ed9b253d8d9f49e7a339955e4e146f8745 (patch) | |
tree | 82c31ccaf5e70d8c2d9c521f4df298d5c3212e24 /mbbsd | |
parent | 7c0ba619849bd02fda9ee3f8b3d2ee6eb9180fdf (diff) | |
download | pttbbs-a0f730ed9b253d8d9f49e7a339955e4e146f8745.tar pttbbs-a0f730ed9b253d8d9f49e7a339955e4e146f8745.tar.gz pttbbs-a0f730ed9b253d8d9f49e7a339955e4e146f8745.tar.bz2 pttbbs-a0f730ed9b253d8d9f49e7a339955e4e146f8745.tar.lz pttbbs-a0f730ed9b253d8d9f49e7a339955e4e146f8745.tar.xz pttbbs-a0f730ed9b253d8d9f49e7a339955e4e146f8745.tar.zst pttbbs-a0f730ed9b253d8d9f49e7a339955e4e146f8745.zip |
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
Diffstat (limited to 'mbbsd')
-rw-r--r-- | mbbsd/edit.c | 24 |
1 files changed, 16 insertions, 8 deletions
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; |