From e5ee21752e651dd5e658632e5d1869b360d573d2 Mon Sep 17 00:00:00 2001 From: kcwu Date: Tue, 16 Jun 2009 07:17:40 +0000 Subject: * fix compile error * fix boundary condition if uid == MAX_USERS git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4634 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- daemon/utmpd/friend.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'daemon/utmpd/friend.cpp') diff --git a/daemon/utmpd/friend.cpp b/daemon/utmpd/friend.cpp index e62a7198..5497ee2e 100644 --- a/daemon/utmpd/friend.cpp +++ b/daemon/utmpd/friend.cpp @@ -13,8 +13,8 @@ /* 除了 user 及 utmp 之外, 全部的 ref index 都是雙向的, 確保 insert & delete O(1) */ /* 當沒有人 refer 時則 resource recycle */ -typedef int Uid; -typedef int Idx; +typedef int Uid; /* 1 <= x <= MAX_USERS */ +typedef int Idx; /* 0 <= x < USHM_SIZE */ struct Relation { @@ -226,10 +226,20 @@ struct BBSUser { utmplist.append(utmpidx); online++; assert(online==utmplist.n); - for(int i=0; i= likehim[i] || likehim[i] > MAX_USERS) { + fprintf(stderr, "bad %d's likehim[%d]=%d\n", utmpidx, i, likehim[i]); + continue; + } like.add(me, likehim[i]); - for(int i=0; i= hatehim[i] || likehim[i] > MAX_USERS) { + fprintf(stderr, "bad %d's hatehim[%d]=%d\n", utmpidx, i, hatehim[i]); + continue; + } hate.add(me, hatehim[i]); + } } void logout(int utmpidx) { @@ -255,15 +265,15 @@ struct BBSUser { }; struct UserList { - BBSUser users[MAX_USERS]; + BBSUser users[MAX_USERS+1]; // [1~MAX_USERS] (0 is unused), UserList() { - for(int i=0; i