summaryrefslogtreecommitdiffstats
path: root/mbbsd/cache.c
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-05-04 21:50:26 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-05-04 21:50:26 +0800
commit56ce644a35d7da469905e786bc50b56f5454b034 (patch)
tree220b597400561e47501ad2ca3a61f9e9297c7e5f /mbbsd/cache.c
parentc8185f580f71fb0b8279401fa9b13c7f84895a5a (diff)
downloadpttbbs-56ce644a35d7da469905e786bc50b56f5454b034.tar
pttbbs-56ce644a35d7da469905e786bc50b56f5454b034.tar.gz
pttbbs-56ce644a35d7da469905e786bc50b56f5454b034.tar.bz2
pttbbs-56ce644a35d7da469905e786bc50b56f5454b034.tar.lz
pttbbs-56ce644a35d7da469905e786bc50b56f5454b034.tar.xz
pttbbs-56ce644a35d7da469905e786bc50b56f5454b034.tar.zst
pttbbs-56ce644a35d7da469905e786bc50b56f5454b034.zip
avoid infinite loop
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@145 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/cache.c')
-rw-r--r--mbbsd/cache.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/mbbsd/cache.c b/mbbsd/cache.c
index dd00d010..fef81942 100644
--- a/mbbsd/cache.c
+++ b/mbbsd/cache.c
@@ -1,4 +1,4 @@
-/* $Id: cache.c,v 1.21 2002/04/28 19:35:28 in2 Exp $ */
+/* $Id: cache.c,v 1.22 2002/05/04 13:50:26 in2 Exp $ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -165,13 +165,17 @@ void attach_uhash() {
void add_to_uhash(int n, char *id) {
int *p, h = StringHash(id);
+ int times;
strcpy(uhash->userid[n], id);
p = &(uhash->hash_head[h]);
-
- while(*p != -1)
+
+ for( times = 0 ; times < MAX_USERS && *p != -1 ; ++times )
p = &(uhash->next_in_hash[*p]);
-
+
+ if( times == MAX_USERS )
+ abort_bbs(0);
+
uhash->next_in_hash[*p = n] = -1;
}
@@ -180,9 +184,14 @@ void add_to_uhash(int n, char *id) {
void remove_from_uhash(int n) {
int h = StringHash(uhash->userid[n]);
int *p = &(uhash->hash_head[h]);
-
- while(*p != -1 && *p != n)
+ int times;
+
+ for( times = 0 ; times < MAX_USERS && (*p != -1 && *p != n); ++times )
p = &(uhash->next_in_hash[*p]);
+
+ if( times == MAX_USERS )
+ abort_bbs(0);
+
if(*p == n)
*p = uhash->next_in_hash[n];
}
@@ -207,18 +216,18 @@ int moneyof(int uid){ /* ptt 改進金錢處理效率 */
return uhash->money[uid-1];
}
int searchuser(char *userid) {
- int h,p;
-
+ int h, p, times;
h = StringHash(userid);
p = uhash->hash_head[h];
- while(p != -1) {
+ for( times = 0 ; times < MAX_USERS && p != -1 ; ++times ){
if(strcasecmp(uhash->userid[p],userid) == 0) {
strcpy(userid,uhash->userid[p]);
return p + 1;
}
p = uhash->next_in_hash[p];
}
+
return 0;
}