diff options
author | robertabcd <robertabcd@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2014-06-25 15:43:44 +0800 |
---|---|---|
committer | robertabcd <robertabcd@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2014-06-25 15:43:44 +0800 |
commit | 813f52add283cb31cb21be8192a8f5a66953b00a (patch) | |
tree | 1c37e47f7e9dddcf88c8731d9da4d6ac299bd596 | |
parent | b6bf009ed80da05dc716cbadf08467454428d830 (diff) | |
download | pttbbs-813f52add283cb31cb21be8192a8f5a66953b00a.tar pttbbs-813f52add283cb31cb21be8192a8f5a66953b00a.tar.gz pttbbs-813f52add283cb31cb21be8192a8f5a66953b00a.tar.bz2 pttbbs-813f52add283cb31cb21be8192a8f5a66953b00a.tar.lz pttbbs-813f52add283cb31cb21be8192a8f5a66953b00a.tar.xz pttbbs-813f52add283cb31cb21be8192a8f5a66953b00a.tar.zst pttbbs-813f52add283cb31cb21be8192a8f5a66953b00a.zip |
Fix bug that not handling EOF correctly in |thread()| and |search_read()|.
This commit also switch API from |get_record_keep()| to |get_records_keep()|.
Note that |rk| < 0 implies |fd| < 0, there is no need to check |fd|.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk@6011 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | pttbbs/mbbsd/read.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/pttbbs/mbbsd/read.c b/pttbbs/mbbsd/read.c index a7897a3a..27694488 100644 --- a/pttbbs/mbbsd/read.c +++ b/pttbbs/mbbsd/read.c @@ -289,10 +289,7 @@ thread(const keeploc_t * locmem, int stypen) new_ln > 0 && new_ln <= last_line && --jump > 0; new_ln += step ) { - int rk = - get_record_keep(currdirect, &fh, sizeof(fileheader_t), new_ln, &fd); - - if(fd < 0 || rk < 0) + if (get_records_keep(currdirect, &fh, sizeof(fileheader_t), new_ln, 1, &fd) <= 0) { new_ln = pos; break; @@ -356,8 +353,8 @@ search_read(const int bid, const keeploc_t * locmem, int stypen) /* First load the timestamp of article where cursor points to */ reload_fh: - rk = get_record_keep(currdirect, &fh, sizeof(fileheader_t), pos, &fd); - if( fd < 0 || rk < 0 ) return pos; + rk = get_records_keep(currdirect, &fh, sizeof(fileheader_t), pos, 1, &fd); + if( rk < 0 ) goto out; if( rk == 0 /* EOF */ ) { /* 如果是置底文章, 則要將 ftime 設定成最大 (代表比最後一篇還要新) */ ftime = 2147483647; @@ -384,8 +381,9 @@ reload_fh: int i; for( i = last_line; i >= 0; --i ) { - rk = get_record_keep(currdirect, &fh, sizeof(fileheader_t), i, &fd); - if( fd < 0 || rk < 0) goto out; + rk = get_records_keep(currdirect, &fh, sizeof(fileheader_t), i, 1, &fd); + if (rk < 0) goto out; + if (rk == 0) continue; if( 0 == brc_unread( bid, fh.filename, 0 ) ) { pos = i; goto out; @@ -397,8 +395,9 @@ reload_fh: /* find out the position for the article result */ for( i = pos; i >= 0 && i <= last_line; i += step ) { - rk = get_record_keep(currdirect, &fh, sizeof(fileheader_t), i, &fd); - if( fd < 0 || rk < 0) goto out; + rk = get_records_keep(currdirect, &fh, sizeof(fileheader_t), i, 1, &fd); + if (rk < 0) goto out; + if (rk == 0) continue; #ifdef SAFE_ARTICLE_DELETE if (fh.filename[0] == '.' || fh.owner[0] == '-') { /* 這篇文章已被刪除, 跳過, 試試下一篇 */ |