summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-04-14 22:53:05 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-04-14 22:53:05 +0800
commitd43fb8c1772b0510f9396e4f023c4aefad06d728 (patch)
treed63b89e0773fb6ed0b5326095d10f345fe9e298a
parenta9253065d48fb023ce89289b9ee481fa38f55687 (diff)
downloadpttbbs-d43fb8c1772b0510f9396e4f023c4aefad06d728.tar
pttbbs-d43fb8c1772b0510f9396e4f023c4aefad06d728.tar.gz
pttbbs-d43fb8c1772b0510f9396e4f023c4aefad06d728.tar.bz2
pttbbs-d43fb8c1772b0510f9396e4f023c4aefad06d728.tar.lz
pttbbs-d43fb8c1772b0510f9396e4f023c4aefad06d728.tar.xz
pttbbs-d43fb8c1772b0510f9396e4f023c4aefad06d728.tar.zst
pttbbs-d43fb8c1772b0510f9396e4f023c4aefad06d728.zip
fix bug in friend_load_real()
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1761 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--mbbsd/friend.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/mbbsd/friend.c b/mbbsd/friend.c
index baf7a47c..92eadb22 100644
--- a/mbbsd/friend.c
+++ b/mbbsd/friend.c
@@ -264,7 +264,7 @@ inline void friend_load_real(int tosort, int maxf,
}
else{
tarray = (int *)malloc(sizeof(int) * maxf);
- --maxf; /* XXX? */
+ --maxf; /* 因為最後一個要填 0, 所以先扣一個回來 */
while( fgets(genbuf, STRLEN, fp) && nFriends < maxf )
if( strtok(genbuf, str_space) &&
(uid = searchuser(genbuf)) )
@@ -273,10 +273,10 @@ inline void friend_load_real(int tosort, int maxf,
if( tosort )
qsort(tarray, nFriends, sizeof(int), qsort_intcompar);
- tarray[nFriends++] = 0;
- memcpy(destar, tarray, sizeof(int) * nFriends);
if( destn )
*destn = nFriends;
+ tarray[nFriends] = 0;
+ memcpy(destar, tarray, sizeof(int) * (nFriends + 1));
free(tarray);
}
}