Mercurial > emacs
comparison lib-src/update-game-score.c @ 104955:be5f5f7e93cb
(main): Sort scores before trimming them,
reported by Jason Feng <jfeng@ozbert.com> (bug#4397).
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Fri, 11 Sep 2009 19:11:07 +0000 |
parents | a9f7e446141d |
children | efc95dcaa727 |
comparison
equal
deleted
inserted
replaced
104954:2a33efb3a1e3 | 104955:be5f5f7e93cb |
---|---|
252 { | 252 { |
253 unlock_file (scorefile, lockstate); | 253 unlock_file (scorefile, lockstate); |
254 lose_syserr ("Failed to read scores file"); | 254 lose_syserr ("Failed to read scores file"); |
255 } | 255 } |
256 push_score (&scores, &scorecount, newscore, user_id, newdata); | 256 push_score (&scores, &scorecount, newscore, user_id, newdata); |
257 sort_scores (scores, scorecount, reverse); | |
257 /* Limit the number of scores. If we're using reverse sorting, then | 258 /* Limit the number of scores. If we're using reverse sorting, then |
258 we should increment the beginning of the array, to skip over the | 259 we should increment the beginning of the array, to skip over the |
259 *smallest* scores. Otherwise, we just decrement the number of | 260 *smallest* scores. Otherwise, we just decrement the number of |
260 scores, since the smallest will be at the end. */ | 261 scores, since the smallest will be at the end. */ |
261 if (scorecount > MAX_SCORES) | 262 if (scorecount > MAX_SCORES) |
262 scorecount -= (scorecount - MAX_SCORES); | 263 scorecount -= (scorecount - MAX_SCORES); |
263 if (reverse) | 264 if (reverse) |
264 scores += (scorecount - MAX_SCORES); | 265 scores += (scorecount - MAX_SCORES); |
265 sort_scores (scores, scorecount, reverse); | |
266 if (write_scores (scorefile, scores, scorecount) < 0) | 266 if (write_scores (scorefile, scores, scorecount) < 0) |
267 { | 267 { |
268 unlock_file (scorefile, lockstate); | 268 unlock_file (scorefile, lockstate); |
269 lose_syserr ("Failed to write scores file"); | 269 lose_syserr ("Failed to write scores file"); |
270 } | 270 } |