From 399423199e47788a2fa68f6f78fb9f9eff9f0443 Mon Sep 17 00:00:00 2001
From: scw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>
Date: Sun, 28 Aug 2005 09:49:35 +0000
Subject:  * fix crash when using 'i' to add board in my favorite  * boundry
 check in move_in_folder()

git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3101 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
---
 mbbsd/board.c | 3 +--
 mbbsd/fav.c   | 6 ++++--
 2 files changed, 5 insertions(+), 4 deletions(-)

(limited to 'mbbsd')

diff --git a/mbbsd/board.c b/mbbsd/board.c
index fc965804..f9331bc2 100644
--- a/mbbsd/board.c
+++ b/mbbsd/board.c
@@ -1151,8 +1151,7 @@ choose_board(int newflag)
 			else {
 			    ptr->attr |= NBRD_FAV;
 
-			    // FIXME �b�Ū� folder 'i' �O����
-			    if (ch == 'i')
+			    if (ch == 'i' && get_data_number(get_current_fav()) > 1)
 				move_in_current_folder(brdnum, num);
 			    else
 				num = brdnum;
diff --git a/mbbsd/fav.c b/mbbsd/fav.c
index 35c3f417..56b3b8c3 100644
--- a/mbbsd/fav.c
+++ b/mbbsd/fav.c
@@ -809,13 +809,15 @@ static void move_in_folder(fav_t *fav, int src, int dst)
     dirty = 1;
 
     /* Find real locations of src and dst in fav->favh[] */
-    for(count = i = 0; count <= src; i++)
+    for(count = i = 0; count <= src && i < fav->DataTail; i++)
 	if (valid_item(&fav->favh[i]))
 	    count++;
+    if (count != src + 1) return;
     src = i - 1;
-    for(count = i = 0; count <= dst; i++)
+    for(count = i = 0; count <= dst && i < fav->DataTail; i++)
 	if (valid_item(&fav->favh[i]))
 	    count++;
+    if (count != dst + 1) return;
     dst = i - 1;
 
     fav_item_copy(&tmp, &fav->favh[src]);
-- 
cgit v1.2.3