diff options
-rw-r--r-- | include/pttstruct.h | 8 | ||||
-rw-r--r-- | mbbsd/admin.c | 2 | ||||
-rw-r--r-- | mbbsd/bbs.c | 4 | ||||
-rw-r--r-- | mbbsd/cache.c | 29 | ||||
-rw-r--r-- | mbbsd/cal.c | 3 | ||||
-rw-r--r-- | mbbsd/mbbsd.c | 7 |
6 files changed, 25 insertions, 28 deletions
diff --git a/include/pttstruct.h b/include/pttstruct.h index 8d9d1e27..ce5b5382 100644 --- a/include/pttstruct.h +++ b/include/pttstruct.h @@ -82,11 +82,11 @@ typedef struct userec_t { unsigned char state; unsigned char pager; unsigned char invisible; - unsigned int exmailbox; + unsigned int exmailbox; // TODO short 就夠了 chicken_t mychicken; time4_t lastsong; unsigned int loginview; - unsigned char channel; /* 動態看板 (unused?) */ + unsigned char channel; /* TODO unused */ unsigned short vl_count; /* ViolateLaw counter */ unsigned short five_win; unsigned short five_lose; @@ -469,7 +469,7 @@ typedef struct { /* brdshm */ int BMcache[MAX_BOARD][MAX_BMs]; boardheader_t bcache[MAX_BOARD]; - int bsorted[2][MAX_BOARD]; /* 0: by name 1: by class */ + int bsorted[2][MAX_BOARD]; /* 0: by name 1: by class */ /* 裡頭存的是 bid-1 */ #if HOTBOARDCACHE unsigned char nHOTs; int HBcache[HOTBOARDCACHE]; @@ -477,7 +477,7 @@ typedef struct { time4_t busystate_b[MAX_BOARD]; int total[MAX_BOARD]; unsigned char n_bottom[MAX_BOARD]; /* number of bottom */ - int hbfl[MAX_BOARD][MAX_FRIEND + 1]; + int hbfl[MAX_BOARD][MAX_FRIEND + 1]; /* hidden board friend list, 0: load time, 1-MAX_FRIEND: uid */ time4_t lastposttime[MAX_BOARD]; time4_t Buptime; time4_t Btouchtime; diff --git a/mbbsd/admin.c b/mbbsd/admin.c index 01b4e3db..f2c6271b 100644 --- a/mbbsd/admin.c +++ b/mbbsd/admin.c @@ -1343,7 +1343,7 @@ give_id_money(char *user_id, int money, FILE * log_fp, char *mail_title, time4_t { char tt[TTLEN + 1] = {0}; - if (deumoney(searchuser(user_id), money) < 0) { + if (deumoney(searchuser(user_id), money) < 0) { // FIXME if searchuser() return 0 move(12, 0); clrtoeol(); prints("id:%s money:%d 不對吧!!", user_id, money); diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index 71f1829b..dab735e2 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -2322,7 +2322,7 @@ good_post(int ent, fileheader_t * fhdr, char *direct) fhdr->filemode = (fhdr->filemode & ~FILE_DIGEST); if (!strcmp(currboard, "Note") || !strcmp(currboard, "PttBug") || !strcmp(currboard, "Artdsn") || !strcmp(currboard, "PttLaw")) { - deumoney(searchuser(fhdr->owner), -1000); + deumoney(searchuser(fhdr->owner), -1000); // FIXME if searchuser() return 0 if (!(currmode & MODE_SELECT)) fhdr->multi.money -= 1000; else @@ -2361,7 +2361,7 @@ good_post(int ent, fileheader_t * fhdr, char *direct) fhdr->filemode = (fhdr->filemode & ~FILE_MARKED) | FILE_DIGEST; if (!strcmp(currboard, "Note") || !strcmp(currboard, "PttBug") || !strcmp(currboard, "Artdsn") || !strcmp(currboard, "PttLaw")) { - deumoney(searchuser(fhdr->owner), 1000); + deumoney(searchuser(fhdr->owner), 1000); // FIXME if searchuser() return 0 if (!(currmode & MODE_SELECT)) fhdr->multi.money += 1000; else diff --git a/mbbsd/cache.c b/mbbsd/cache.c index c5936331..3f989885 100644 --- a/mbbsd/cache.c +++ b/mbbsd/cache.c @@ -555,17 +555,14 @@ reload_bcache(void) for( i = 0 ; i < MAX_BOARD ; ++i ) if( SHM->bcache[i].brdname[0] ){ char fn[128]; - struct stat st; + int n; sprintf(fn, "boards/%c/%s/.DIR.bottom", SHM->bcache[i].brdname[0], SHM->bcache[i].brdname); - if( stat(fn, &st) == -1 ) - SHM->n_bottom[i] = 0; - else { - SHM->n_bottom[i] = st.st_size / sizeof(fileheader_t); - if( SHM->n_bottom[i] > 5 ) - SHM->n_bottom[i] = 5; - } + n = get_num_records(fn, sizeof(fileheader_t)); + if( n > 5 ) + n = 5; + SHM->n_bottom[i] = n; } } @@ -608,7 +605,6 @@ reset_board(int bid) /* XXXbid: from 1 */ safe_sleep(1); } else { SHM->busystate_b[bid] = COMMON_TIME; - nuser = bcache[bid].nuser; bhdr = bcache; bhdr += bid; @@ -757,9 +753,8 @@ void buildBMcache(int bid) /* bid starts from 1 */ { char s[IDLEN * 3 + 3], *ptr; int i, uid; - --bid; - strncpy(s, bcache[bid].BM, sizeof(s)); + strlcpy(s, bcache[bid-1].BM, sizeof(s)); for( i = 0 ; s[i] != 0 ; ++i ) if( !isalpha((int)s[i]) && !isdigit((int)s[i]) ) s[i] = ' '; @@ -768,14 +763,15 @@ void buildBMcache(int bid) /* bid starts from 1 */ i < MAX_BMs && ptr != NULL ; ptr = strtok(NULL, " "), ++i ) if( (uid = searchuser(ptr)) != 0 ) - SHM->BMcache[bid][i] = uid; + SHM->BMcache[bid-1][i] = uid; for( ; i < MAX_BMs ; ++i ) - SHM->BMcache[bid][i] = -1; + SHM->BMcache[bid-1][i] = -1; } int is_BM_cache(int bid) /* bid starts from 1 */ { --bid; + // XXX hard coded MAX_BMs=4 if( currutmp->uid == SHM->BMcache[bid][0] || currutmp->uid == SHM->BMcache[bid][1] || currutmp->uid == SHM->BMcache[bid][2] || @@ -822,8 +818,8 @@ reload_pttcache(void) subitem.filename); if (!(fp2 = fopen(buf, "r"))) continue; - fread(SHM->notes[id], sizeof(char), 200 * 11, fp2); - SHM->notes[id][200 * 11 - 1] = 0; + fread(SHM->notes[id], sizeof(char), sizeof(SHM->notes[0]), fp2); + SHM->notes[id][sizeof(SHM->notes[0]) - 1] = 0; id++; fclose(fp2); if (id >= MAX_MOVIE) @@ -986,7 +982,7 @@ hbflreload(int bid) fclose(fp); } hbfl[0] = COMMON_TIME; - memcpy(SHM->hbfl[bid], hbfl, sizeof(hbfl)); + memcpy(SHM->hbfl[bid], hbfl, sizeof(hbfl)); // FIXME bid-1 ? } int @@ -994,6 +990,7 @@ hbflcheck(int bid, int uid) { int i; + // FIXME bid-1? if (SHM->hbfl[bid][0] < login_start_time - HBFLexpire) hbflreload(bid); for (i = 1; SHM->hbfl[bid][i] != 0 && i <= MAX_FRIEND; ++i) { diff --git a/mbbsd/cal.c b/mbbsd/cal.c index 78011f5f..34eb3ea7 100644 --- a/mbbsd/cal.c +++ b/mbbsd/cal.c @@ -292,6 +292,7 @@ p_exmail() char ans[4], buf[200]; int n; + assert(MAX_EXKEEPMAIL < (1<< (sizeof(cuser.exmailbox)*8-1) )); if (cuser.exmailbox >= MAX_EXKEEPMAIL) { vmsg("容量最多增加 %d 封,不能再買了。", MAX_EXKEEPMAIL); return 0; @@ -373,7 +374,7 @@ p_give() tax = give_tax(money); if (money - tax <= 0) return 0; /* 繳完稅就沒錢給了 */ - deumoney(searchuser(id), money - tax); + deumoney(searchuser(id), money - tax); // FIXME if searchuser(id) return 0 demoney(-money); log_file(FN_MONEY, LOG_CREAT | LOG_VF, "%s\t給%s\t%d\t%s", cuser.userid, id, money - tax, ctime4(&now)); diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index 935111d7..9fc9225f 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -818,9 +818,8 @@ inline static void birthday_make_a_wish(struct tm *ptime, struct tm *tmp){ } } -inline static void record_lasthost(char *fromhost, int len){ - strncpy(cuser.lasthost, fromhost, len); - cuser.lasthost[len - 1] = '\0'; +inline static void record_lasthost(char *fromhost){ + strlcpy(cuser.lasthost, fromhost, sizeof(cuser.lasthost)); } inline static void check_mailbox_quota(void){ @@ -956,7 +955,7 @@ user_login() check_bad_login(); check_mailbox_quota(); check_register(); - record_lasthost(fromhost, 16); + record_lasthost(fromhost); restore_backup(); } else if (!strcmp(cuser.userid, STR_GUEST)) { init_guest_info(); |