diff options
author | kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-02-06 14:57:55 +0800 |
---|---|---|
committer | kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-02-06 14:57:55 +0800 |
commit | 6992814160ed9cb2a62cb6af943d1bf1a0c09f78 (patch) | |
tree | e4fe4980f3e2681567757bf7d9db8258a60e9521 /mbbsd | |
parent | aed0b53aad42a5708d232c1eb44012af4574299c (diff) | |
download | pttbbs-6992814160ed9cb2a62cb6af943d1bf1a0c09f78.tar pttbbs-6992814160ed9cb2a62cb6af943d1bf1a0c09f78.tar.gz pttbbs-6992814160ed9cb2a62cb6af943d1bf1a0c09f78.tar.bz2 pttbbs-6992814160ed9cb2a62cb6af943d1bf1a0c09f78.tar.lz pttbbs-6992814160ed9cb2a62cb6af943d1bf1a0c09f78.tar.xz pttbbs-6992814160ed9cb2a62cb6af943d1bf1a0c09f78.tar.zst pttbbs-6992814160ed9cb2a62cb6af943d1bf1a0c09f78.zip |
logout_friend_online() fault tolerant
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2471 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r-- | mbbsd/talk.c | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/mbbsd/talk.c b/mbbsd/talk.c index 927ec328..f8799f4e 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -259,28 +259,36 @@ void login_friend_online(void) return; } +/* TODO merge with util/shmctl.c logout_friend_online() */ int logout_friend_online(userinfo_t * utmp) { - int i, j, k; + int my_friend_idx, thefriend; + int k; int offset = (int)(utmp - &SHM->uinfo[0]); userinfo_t *ui; - while (utmp->friendtotal > 0) { - i = utmp->friendtotal - 1; - j = (utmp->friend_online[i] & 0xFFFFFF); - utmp->friend_online[i] = 0; - ui = &SHM->uinfo[j]; - if (ui->pid && ui != utmp) { - for (k = 0; k < ui->friendtotal && k < MAX_FRIEND && - (int)(ui->friend_online[k] & 0xFFFFFF) != offset; k++); - if (k < ui->friendtotal) { - ui->friendtotal--; - ui->friend_online[k] = ui->friend_online[ui->friendtotal]; - ui->friend_online[ui->friendtotal] = 0; - } + for(; utmp->friendtotal>0; utmp->friendtotal--) { + if( !(0 <= utmp->friendtotal && utmp->friendtotal < MAX_FRIEND) ) + return 1; + my_friend_idx=utmp->friendtotal-1; + thefriend = (utmp->friend_online[my_friend_idx] & 0xFFFFFF); + utmp->friend_online[my_friend_idx]=0; + + if( !(0 <= thefriend && thefriend < MAX_ACTIVE) ) + continue; + + ui = &SHM->uinfo[thefriend]; + if(ui->pid==0 || ui==utmp) + continue; + if(ui->friendtotal > MAX_FRIEND || ui->friendtotal<0) + continue; + for (k = 0; k < ui->friendtotal && k < MAX_FRIEND && + (int)(ui->friend_online[k] & 0xFFFFFF) != offset; k++); + if (k < ui->friendtotal && k < MAX_FRIEND) { + ui->friendtotal--; + ui->friend_online[k] = ui->friend_online[ui->friendtotal]; + ui->friend_online[ui->friendtotal] = 0; } - utmp->friendtotal--; - utmp->friend_online[utmp->friendtotal] = 0; } return 0; } |