summaryrefslogtreecommitdiffstats
path: root/daemon/utmpd/friend.cpp
diff options
context:
space:
mode:
authorkcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2009-06-16 15:17:40 +0800
committerkcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2009-06-16 15:17:40 +0800
commite5ee21752e651dd5e658632e5d1869b360d573d2 (patch)
treee7add7a89ae7e69df7d80904e803401b5afa60f9 /daemon/utmpd/friend.cpp
parent20e713a15d403569e80a1461634628fb12996a47 (diff)
downloadpttbbs-e5ee21752e651dd5e658632e5d1869b360d573d2.tar
pttbbs-e5ee21752e651dd5e658632e5d1869b360d573d2.tar.gz
pttbbs-e5ee21752e651dd5e658632e5d1869b360d573d2.tar.bz2
pttbbs-e5ee21752e651dd5e658632e5d1869b360d573d2.tar.lz
pttbbs-e5ee21752e651dd5e658632e5d1869b360d573d2.tar.xz
pttbbs-e5ee21752e651dd5e658632e5d1869b360d573d2.tar.zst
pttbbs-e5ee21752e651dd5e658632e5d1869b360d573d2.zip
* 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
Diffstat (limited to 'daemon/utmpd/friend.cpp')
-rw-r--r--daemon/utmpd/friend.cpp26
1 files changed, 18 insertions, 8 deletions
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<MAX_FRIEND && likehim[i]; i++)
+ for(int i=0; i<MAX_FRIEND && likehim[i]; i++) {
+ if (0 >= 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<MAX_REJECT && hatehim[i]; i++)
+ }
+ for(int i=0; i<MAX_REJECT && hatehim[i]; i++) {
+ if (0 >= 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<MAX_USERS; i++)
+ for(int i=0; i<=MAX_USERS; i++)
users[i].me=i;
}
void login(Uid uid, Idx idx, const Uid likehim[MAX_FRIEND], const Uid hatehim[MAX_REJECT]) {
- assert(uid<MAX_USERS);
- assert(idx<USHM_SIZE);
+ assert(1 <= uid && uid<=MAX_USERS);
+ assert(0 < idx && idx<USHM_SIZE);
/* 由於不會收到 logout event, 因此 logout 只發生在 utmp override */
if(utmp.utmp[idx]!=-1) users[utmp.utmp[idx]].logout(idx);
users[uid].login(idx, likehim, hatehim);