unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#8310: update-game-score -r logic broken with MAX_SCORES
@ 2011-03-21  7:37 Paul Eggert
  0 siblings, 0 replies; only message in thread
From: Paul Eggert @ 2011-03-21  7:37 UTC (permalink / raw)
  To: 8310

Here's a bug found by gcc -Wstrict-overflow (GCC 4.5.2) this one in
in update-game-score -r.  I plan to install the following patch.

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).
=== modified file 'lib-src/update-game-score.c'
--- lib-src/update-game-score.c	2011-02-21 18:06:25 +0000
+++ lib-src/update-game-score.c	2011-03-21 07:17:22 +0000
@@ -242,13 +242,15 @@
   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);






^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-03-21  7:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-21  7:37 bug#8310: update-game-score -r logic broken with MAX_SCORES Paul Eggert

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).