From: Paul Eggert Date: Mon, 21 Mar 2011 07:46:53 +0000 (-0700) Subject: update-game-score: fix bug with -r X-Git-Tag: emacs-pretest-24.0.90~104^2~275^2~513^2~18 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f0d80d43baa89029ea030a98350a74793ee5dc89;p=emacs.git update-game-score: fix bug with -r * update-game-score.c (main): Don't set 'scores' to garbage when -r is specified and scorecount != MAX_SCORES. This bug was introduced in the 2002-04-10 change, and was found with gcc -Wstrict-overflow (GCC 4.5.2, x86-64). --- diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index cc713f0b68c..2548561f313 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog @@ -1,5 +1,11 @@ 2011-03-21 Paul Eggert + update-game-score: fix bug with -r + * update-game-score.c (main): Don't set 'scores' to garbage when + -r is specified and scorecount != MAX_SCORES. This bug was + introduced in the 2002-04-10 change, and was found with gcc + -Wstrict-overflow (GCC 4.5.2, x86-64). + fakemail: Remove dependency on ignore-value. This undoes some of the recent fakemail-related changes. It is made possible due to recent changes to gnulib's stdio module. diff --git a/lib-src/update-game-score.c b/lib-src/update-game-score.c index 70b79a64f91..e95e2ce259d 100644 --- a/lib-src/update-game-score.c +++ b/lib-src/update-game-score.c @@ -242,13 +242,15 @@ main (int argc, char **argv) push_score (&scores, &scorecount, newscore, user_id, newdata); sort_scores (scores, scorecount, reverse); /* Limit the number of scores. If we're using reverse sorting, then - we should increment the beginning of the array, to skip over the - *smallest* scores. Otherwise, we just decrement the number of - scores, since the smallest will be at the end. */ + also increment the beginning of the array, to skip over the + *smallest* scores. Otherwise, just decrementing the number of + scores suffices, since the smallest is at the end. */ if (scorecount > MAX_SCORES) - scorecount -= (scorecount - MAX_SCORES); - if (reverse) - scores += (scorecount - MAX_SCORES); + { + if (reverse) + scores += (scorecount - MAX_SCORES); + scorecount = MAX_SCORES; + } if (write_scores (scorefile, scores, scorecount) < 0) { unlock_file (scorefile, lockstate);