diff options
author | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-07-30 14:54:40 +0800 |
---|---|---|
committer | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-07-30 14:54:40 +0800 |
commit | c0c9d87226fcdd179335b6f7356499ce05219b09 (patch) | |
tree | 6fc81a1bab6ff112288402fcef31a9a3425a1e4c | |
parent | 9c890899dc1ffab3a2ba67402c3dcb7b3e0e4f02 (diff) | |
download | pttbbs-c0c9d87226fcdd179335b6f7356499ce05219b09.tar pttbbs-c0c9d87226fcdd179335b6f7356499ce05219b09.tar.gz pttbbs-c0c9d87226fcdd179335b6f7356499ce05219b09.tar.bz2 pttbbs-c0c9d87226fcdd179335b6f7356499ce05219b09.tar.lz pttbbs-c0c9d87226fcdd179335b6f7356499ce05219b09.tar.xz pttbbs-c0c9d87226fcdd179335b6f7356499ce05219b09.tar.zst pttbbs-c0c9d87226fcdd179335b6f7356499ce05219b09.zip |
use correct type: size_t/int/long/pointer
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2153 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | include/convert.h | 2 | ||||
-rw-r--r-- | include/proto.h | 2 | ||||
-rw-r--r-- | mbbsd/bbs.c | 28 | ||||
-rw-r--r-- | mbbsd/board.c | 11 | ||||
-rw-r--r-- | mbbsd/chicken.c | 2 | ||||
-rw-r--r-- | mbbsd/convert.c | 44 | ||||
-rw-r--r-- | mbbsd/guess.c | 22 | ||||
-rw-r--r-- | mbbsd/more.c | 4 | ||||
-rw-r--r-- | mbbsd/passwd.c | 2 | ||||
-rw-r--r-- | mbbsd/read.c | 2 | ||||
-rw-r--r-- | mbbsd/stuff.c | 6 | ||||
-rw-r--r-- | mbbsd/talk.c | 8 | ||||
-rw-r--r-- | mbbsd/topsong.c | 4 | ||||
-rw-r--r-- | mbbsd/vote.c | 2 |
14 files changed, 76 insertions, 63 deletions
diff --git a/include/convert.h b/include/convert.h index 88933d54..9ce0b75a 100644 --- a/include/convert.h +++ b/include/convert.h @@ -6,6 +6,6 @@ #define CONV_GB 1 #define CONV_UTF8 2 -typedef int (* read_write_type)(int, void *, size_t); +typedef ssize_t (* read_write_type)(int, void *, size_t); #endif diff --git a/include/proto.h b/include/proto.h index c2d91f83..2427bbae 100644 --- a/include/proto.h +++ b/include/proto.h @@ -479,7 +479,7 @@ char *Cdate(time_t *clock); void sethomefile(char *buf, char *userid, char *fname); int log_file(char *fn, int flag, const char *fmt,...); void str_lower(char *t, char *s); -int strstr_lower(char *str, char *tag); +void *strstr_lower(char *str, char *tag); int cursor_key(int row, int column); int search_num(int ch, int max); void setuserfile(char *buf, char *fname); diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index df6d86ab..301fbaf3 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -1353,8 +1353,8 @@ do_add_recommend(char *direct, fileheader_t *fhdr, //Ptt: update only necessary if( (fd = open(direct, O_RDWR)) < 0 ) return -1; - if( lseek(fd, (off_t)(sizeof(fileheader_t) * (ent - 1) + - (int)&fhdr->recommend - (int)fhdr), + if( lseek(fd, (sizeof(fileheader_t) * (ent - 1) + + (char *)&fhdr->recommend - (char *)fhdr), SEEK_SET) >= 0 ){ // 如果 lseek 失敗就不會 write read(fd, &fhdr->recommend, sizeof(char)); @@ -1458,9 +1458,10 @@ do_bid(int ent, fileheader_t * fhdr, boardheader_t *bp, } snprintf(genbuf, sizeof(genbuf), - "\033[1;31m→ \033[33m%s\033[m\033[33m:%s\033[m%*s %s%-15d標%15s %02d/%02d\n", - cuser.userid,say, - 31 - strlen(cuser.userid) - strlen(say), " ", + "\033[1;31m→ \033[33m%s\033[m\033[33m:%s\033[m%*s" + "%s%-15d標%15s %02d/%02d\n", + cuser.userid, say, + (int)(31 - strlen(cuser.userid) - strlen(say)), " ", money, next, fromhost, ptime->tm_mon + 1, ptime->tm_mday); @@ -1478,9 +1479,10 @@ do_bid(int ent, fileheader_t * fhdr, boardheader_t *bp, strcpy(bidinfo.userid, cuser.userid); snprintf(genbuf, sizeof(genbuf), - "\033[1;31m→ \033[33m自動競標%s勝出\033[m\033[33m\033[m%*s%s%-15d標 %02d/%02d\n", + "\033[1;31m→ \033[33m自動競標%s勝出\033" + "[m\033[33m\033[m%*s%s%-15d標 %02d/%02d\n", cuser.userid, - 20 - strlen(cuser.userid) , " ",money, + (int)(20 - strlen(cuser.userid)), " ", money, bidinfo.high, ptime->tm_mon + 1, ptime->tm_mday); do_add_recommend(direct, fhdr, ent, genbuf, 0); @@ -1491,9 +1493,10 @@ do_bid(int ent, fileheader_t * fhdr, boardheader_t *bp, else bidinfo.high=bidinfo.usermax; /*這邊怪怪的*/ snprintf(genbuf, sizeof(genbuf), - "\033[1;31m→ \033[33m自動競標%s勝出\033[m\033[33m\033[m%*s%s%-15d標 %02d/%02d\n", + "\033[1;31m→ \033[33m自動競標%s勝出" + "\033[m\033[33m\033[m%*s%s%-15d標 %02d/%02d\n", bidinfo.userid, - 20 - strlen(bidinfo.userid) , " ", money, + (int)(20 - strlen(bidinfo.userid)), " ", money, bidinfo.high, ptime->tm_mon + 1, ptime->tm_mday); do_add_recommend(direct, fhdr, ent, genbuf, 0); @@ -1563,17 +1566,18 @@ recommend(int ent, fileheader_t * fhdr, char *direct) #ifdef OLDRECOMMEND snprintf(buf, sizeof(buf), - "\033[1;31m→ \033[33m%s\033[m\033[33m:%s\033[m%*s推%15s %02d/%02d\n", + "\033[1;31m→ \033[33m%s\033[m\033[33m:%s\033[m%*s" + "推%15s %02d/%02d\n", cuser.userid, path, 51 - strlen(cuser.userid) - strlen(path), " ", fromhost, ptime->tm_mon + 1, ptime->tm_mday); #else snprintf(buf, sizeof(buf), - "\033[1;%s \033[33m%s\033[m\033[33m:%s\033[m%*s%15s %02d/%02d\n", + "\033[1;%s \033[33m%s\033[m\033[33m:%s\033[m%*s%15s %02d/%02d\n", ctype[type], cuser.userid, path, - 53 - strlen(cuser.userid) - strlen(path) , + (int)(53 - strlen(cuser.userid) - strlen(path)), " ", fromhost, ptime->tm_mon + 1, ptime->tm_mday); diff --git a/mbbsd/board.c b/mbbsd/board.c index fb69c8f1..a7c52332 100644 --- a/mbbsd/board.c +++ b/mbbsd/board.c @@ -200,9 +200,13 @@ load_boards(char *key) } if (class_bid <= 0) { if( yank_flag == 0 ){ // fav mode - fav_t *fav = get_current_fav(); - - nbrd = (boardstat_t *)malloc(sizeof(boardstat_t) * get_data_number(fav)); + fav_t *fav = get_current_fav(); + int nfav = get_data_number(fav); + if( nfav == 0 ){ + nbrd = (boardstat_t *)malloc(sizeof(boardstat_t) * 1); + goto EMPTYFAV; + } + nbrd = (boardstat_t *)malloc(sizeof(boardstat_t) * nfav); for( i = 0 ; i < fav->DataTail; ++i ){ int state; if (!(fav->favh[i].attr & FAVH_FAV)) @@ -247,6 +251,7 @@ load_boards(char *key) state |= NBRD_TAG; addnewbrdstat(fav_getid(&fav->favh[i]) - 1, NBRD_FAV | state); } + EMPTYFAV: if (brdnum == 0) addnewbrdstat(0, 0); } diff --git a/mbbsd/chicken.c b/mbbsd/chicken.c index 2b3948e9..26bf1a95 100644 --- a/mbbsd/chicken.c +++ b/mbbsd/chicken.c @@ -176,7 +176,7 @@ show_chicken_stat(chicken_t * thechicken) "\033[33m%-7d\033[m 大補丸:\033[33m%-7d\033[m 藥品 :\033[33m%-7d" "\033[m \n", thechicken->name, chicken_type[(int)thechicken->type], - 15 - strlen(thechicken->name), "", + (int)(15 - strlen(thechicken->name)), "", ptime->tm_year % 100, ptime->tm_mon + 1, ptime->tm_mday, cage[age > 16 ? 16 : age], age, thechicken->hp, thechicken->hp_max, thechicken->mm, thechicken->mm_max, diff --git a/mbbsd/convert.c b/mbbsd/convert.c index f07e21db..ff9fef5c 100644 --- a/mbbsd/convert.c +++ b/mbbsd/convert.c @@ -6,44 +6,48 @@ extern read_write_type write_type; extern read_write_type read_type; -unsigned char *gb2big(unsigned char *, int* , int); -unsigned char *big2gb(unsigned char *, int* , int); +unsigned char *gb2big(unsigned char *, int *, int); +unsigned char *big2gb(unsigned char *, int *, int); unsigned char *utf8_uni(unsigned char *, int *, int); unsigned char *uni_utf8(unsigned char *, int *, int); -unsigned char *uni2big(unsigned char *, int* , int); -unsigned char *big2uni(unsigned char *, int* , int); +unsigned char *uni2big(unsigned char *, int *, int); +unsigned char *big2uni(unsigned char *, int *, int); -static int gb_read(int fd, void *buf, size_t count) +static ssize_t gb_read(int fd, void *buf, size_t count) { - count = read(fd, buf, count); + int icount = (int)read(fd, buf, count); if (count > 0) - gb2big((char *)buf, &count, 0); - return count; + gb2big((char *)buf, &icount, 0); + return (size_t)icount; } -static int gb_write(int fd, void *buf, size_t count) +static ssize_t gb_write(int fd, void *buf, size_t count) { - big2gb((char *)buf, &count, 0); - return write(fd, buf, count); + int icount = (int)count; + big2gb((char *)buf, &icount, 0); + return write(fd, buf, (size_t)icount); } -static int utf8_read(int fd, void *buf, size_t count) +static ssize_t utf8_read(int fd, void *buf, size_t count) { count = read(fd, buf, count); if (count > 0) { - utf8_uni(buf, &count, 0); - uni2big(buf, &count, 0); - ((char *)buf)[count] = 0; + int icount = (int)count; + utf8_uni(buf, &icount, 0); + uni2big(buf, &icount, 0); + ((char *)buf)[icount] = 0; + return (size_t)icount; } return count; } -static int utf8_write(int fd, void *buf, size_t count) +static ssize_t utf8_write(int fd, void *buf, size_t count) { - big2uni(buf, &count, 0); - uni_utf8(buf, &count, 0); - ((char *)buf)[count] = 0; - return write(fd, buf, count); + int icount = (int)count; + big2uni(buf, &icount, 0); + uni_utf8(buf, &icount, 0); + ((char *)buf)[icount] = 0; + return write(fd, buf, (size_t)icount); } void set_converting_type(int which) diff --git a/mbbsd/guess.c b/mbbsd/guess.c index 98425b66..77914147 100644 --- a/mbbsd/guess.c +++ b/mbbsd/guess.c @@ -246,7 +246,7 @@ guess_main(void) Diff_Random(answer); move(2, 0); clrtoeol(); - prints("您下注 :%lu Ptt$", money); + prints("您下注 :%d Ptt$", money); getdata_str(4, 0, "您要和電腦比賽嗎? <y/n>[y]:", ifcomputer, sizeof(ifcomputer), LCECHO, "y"); @@ -292,29 +292,29 @@ guess_main(void) if (count > c_count) { outs("你輸給電腦了"); move(18, 35); - prints("你賠了 %lu ", money); + prints("你賠了 %d ", money); if ((file = fopen(LOGPASS, "a"))) { fprintf(file, "電腦第%d次猜中, ", c_count); if (youwin) fprintf(file, "%s 第%d次猜中, ", cuser.userid, count); else fprintf(file, "%s 沒猜中, ", cuser.userid); - fprintf(file, "電腦賺走了%s %ld Ptt$\n", cuser.userid, money); + fprintf(file, "電腦賺走了%s %d Ptt$\n", cuser.userid, money); fclose(file); } } else if (count < c_count) { outs("真厲害, 讓你賺到囉"); move(18, 35); - prints("你賺走了 %lu ", money * 2); + prints("你賺走了 %d ", money * 2); demoney(money * 2); if ((file = fopen(LOGPASS, "a"))) { fprintf(file, "id: %s, 第%d次猜中, 電腦第%d次猜中, " - "贏了電腦 %ld Ptt$\n", cuser.userid, count, + "贏了電腦 %d Ptt$\n", cuser.userid, count, c_count, money * 2); fclose(file); } } else { - prints("真厲害, 和電腦打成平手了, 拿回本錢%lu\n", money); + prints("真厲害, 和電腦打成平手了, 拿回本錢%d\n", money); demoney(money); if ((file = fopen(LOGPASS, "a"))) { fprintf(file, "id: %s 和電腦打成了平手\n", cuser.userid); @@ -330,14 +330,14 @@ guess_main(void) if (count < 5) { outs("真厲害, 錢被你賺走了"); if ((file = fopen(LOGPASS, "a"))) { - fprintf(file, "id: %s, 第%d次猜中, 贏了 %ld Ptt$\n", + fprintf(file, "id: %s, 第%d次猜中, 贏了 %d Ptt$\n", cuser.userid, count, TABLE[count] * money); fclose(file); } } else if (count > 5) { outs("唉, 太多次才猜出來了"); if ((file = fopen(LOGPASS, "a"))) { - fprintf(file, "id: %s, 第%d次才猜中, 賠了 %ld Ptt$\n", + fprintf(file, "id: %s, 第%d次才猜中, 賠了 %d Ptt$\n", cuser.userid, count, money); fclose(file); } @@ -345,9 +345,9 @@ guess_main(void) outs("五次猜出來, 還你本錢吧"); move(18, 35); clrtoeol(); - prints("你拿回了%lu Ptt$\n", money); + prints("你拿回了%d Ptt$\n", money); if ((file = fopen(LOGPASS, "a"))) { - fprintf(file, "id: %s, 第%d次猜中, 拿回了本錢 %lu Ptt$\n", + fprintf(file, "id: %s, 第%d次猜中, 拿回了本錢 %d Ptt$\n", cuser.userid, count, money); fclose(file); } @@ -361,7 +361,7 @@ guess_main(void) move(18, 35); outs("下次再來吧"); if ((file = fopen(BBSHOME "/etc/loseguess.log", "a"))) { - fprintf(file, "id: %s 賭了 %ld Ptt$\n", cuser.userid, money); + fprintf(file, "id: %s 賭了 %d Ptt$\n", cuser.userid, money); fclose(file); } unlockutmpmode(); diff --git a/mbbsd/more.c b/mbbsd/more.c index 1524ba28..5feb34b7 100644 --- a/mbbsd/more.c +++ b/mbbsd/more.c @@ -239,12 +239,12 @@ more(char *fpath, int promptend) SearchStr[strlen(search_str)] = 0; searching = 0; snprintf(msg, sizeof(msg), - "%.*s\033[7m%s\033[m", pos - buf, buf, + "%.*s\033[7m%s\033[m", (int)(pos - buf), buf, SearchStr); while ((pos = fptr(pos1 = pos + strlen(search_str), search_str))) { snprintf(buf1, sizeof(buf1), - "%.*s\033[7m%s\033[m", pos - pos1, + "%.*s\033[7m%s\033[m", (int)(pos - pos1), pos1, SearchStr); strlcat(msg, buf1, sizeof(msg)); } diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c index 88bfcaf7..6d25761b 100644 --- a/mbbsd/passwd.c +++ b/mbbsd/passwd.c @@ -62,7 +62,7 @@ passwd_update_money(int num) if ((pwdfd = open(fn_passwd, O_WRONLY)) < 0) exit(1); lseek(pwdfd, sizeof(userec_t) * (num - 1) + - ((int)&u.money - (int)&u), SEEK_SET); + ((char *)&u.money - (char *)&u), SEEK_SET); write(pwdfd, &money, sizeof(int)); close(pwdfd); return 0; diff --git a/mbbsd/read.c b/mbbsd/read.c index 3dfac5cf..394984e4 100644 --- a/mbbsd/read.c +++ b/mbbsd/read.c @@ -379,7 +379,7 @@ select_read(keeploc_t * locmem, int sr_mode) snprintf(genbuf, sizeof(genbuf), "%s%X.%X.%X", p ? p : "SR.", - sr_mode, strlen(keyword), StringHash(keyword)); + sr_mode, (int)strlen(keyword), StringHash(keyword)); if( strlen(genbuf) > MAXPATHLEN - 50 ) return READ_REDRAW; // avoid overflow diff --git a/mbbsd/stuff.c b/mbbsd/stuff.c index a893db25..516208cc 100644 --- a/mbbsd/stuff.c +++ b/mbbsd/stuff.c @@ -128,13 +128,13 @@ str_lower(char *t, char *s) } while (ch); } -int +void * strstr_lower(char *str, char *tag) { char buf[STRLEN]; str_lower(buf, str); - return (int)strstr(buf, tag); + return strstr(buf, tag); } void @@ -725,7 +725,7 @@ StringHash(unsigned char *s) v = (v << 8) | (v >> 24); v ^= toupper(*s++); /* note this is case insensitive */ } - return (v * 2654435769UL) >> (32 - HASH_BITS); + return (v * 2654435769U) >> (32 - HASH_BITS); } inline int *intbsearch(int key, int *base0, int nmemb) diff --git a/mbbsd/talk.c b/mbbsd/talk.c index 8edf5980..2ae1f5ed 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -384,7 +384,7 @@ my_query(char *uident) prints("《ID暱稱》%s(%s)%*s《經濟狀況》%s", muser.userid, muser.username, - 26 - strlen(muser.userid) - strlen(muser.username), "", + (int)(26 - strlen(muser.userid) - strlen(muser.username)), "", money[i]); if (uentp && ((fri_stat & HFM && !uentp->invisible) || strcmp(muser.userid,cuser.userid) == 0)) prints(" ($%d)", muser.money); @@ -1567,9 +1567,9 @@ t_showhelp() static char * friend_descript(userinfo_t * uentp, char *desc_buf, int desc_buflen) { - char *space_buf = ""; + char *space_buf = "", *flag; char fpath[80], name[IDLEN + 2], *desc, *ptr; - int len, flag; + int len; FILE *fp; char genbuf[STRLEN]; @@ -1584,7 +1584,7 @@ friend_descript(userinfo_t * uentp, char *desc_buf, int desc_buflen) desc = genbuf + 13; /* TODO maybe none linear search, or fread, or cache */ - while ((flag = (int)fgets(genbuf, STRLEN, fp))) { + while ((flag = fgets(genbuf, STRLEN, fp))) { if (!memcmp(genbuf, name, len)) { if ((ptr = strchr(desc, '\n'))) ptr[0] = '\0'; diff --git a/mbbsd/topsong.c b/mbbsd/topsong.c index cb71ac5b..073f0138 100644 --- a/mbbsd/topsong.c +++ b/mbbsd/topsong.c @@ -70,9 +70,9 @@ sortsong() fprintf(fo, " \033[36m──\033[37m名次\033[36m──────\033[37m歌" " 名\033[36m───────────\033[37m次數\033[36m" - "──\033[32m共%ld次\033[36m──\033[m\n", totalcount); + "──\033[32m共%d次\033[36m──\033[m\n", totalcount); for (n = 0; n < 100 && songs[n].name[0]; n++) { - fprintf(fo, " %5d. %-38.38s %4ld \033[32m[%.2f]\033[m\n", n + 1, + fprintf(fo, " %5d. %-38.38s %4d \033[32m[%.2f]\033[m\n", n + 1, songs[n].name, songs[n].count, (float)songs[n].count / totalcount); } diff --git a/mbbsd/vote.c b/mbbsd/vote.c index e08431ae..a006cd3b 100644 --- a/mbbsd/vote.c +++ b/mbbsd/vote.c @@ -454,7 +454,7 @@ vote_view(char *bname, int vote_index) counts = (int *)malloc(item_num * sizeof(int)); prints("\n◆ 預知投票紀事: 每人最多可投 %d 票,目前共有 %d 票,\n" - "本次投票將結束於 %s", atoi(inbuf), (num / sizeof(short)), + "本次投票將結束於 %s", atoi(inbuf), (int)(num / sizeof(short)), ctime(&closetime)); /* Thor: 開放 票數 預知 */ |