From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#8310: update-game-score -r logic broken with MAX_SCORES Date: Mon, 21 Mar 2011 00:37:09 -0700 Organization: UCLA Computer Science Department Message-ID: <4D870025.8010702@cs.ucla.edu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1300694847 11300 80.91.229.12 (21 Mar 2011 08:07:27 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 21 Mar 2011 08:07:27 +0000 (UTC) To: 8310@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Mar 21 09:07:18 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Q1a8z-0000To-Ck for geb-bug-gnu-emacs@m.gmane.org; Mon, 21 Mar 2011 09:07:18 +0100 Original-Received: from localhost ([127.0.0.1]:36912 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q1a8x-0007AI-4T for geb-bug-gnu-emacs@m.gmane.org; Mon, 21 Mar 2011 04:07:15 -0400 Original-Received: from [140.186.70.92] (port=45873 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q1a8n-00079j-JI for bug-gnu-emacs@gnu.org; Mon, 21 Mar 2011 04:07:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q1a8l-0001ku-OZ for bug-gnu-emacs@gnu.org; Mon, 21 Mar 2011 04:07:04 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:54263) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q1a8l-0001kp-Lt for bug-gnu-emacs@gnu.org; Mon, 21 Mar 2011 04:07:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1Q1Zgg-0005Jn-KY; Mon, 21 Mar 2011 03:38:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 21 Mar 2011 07:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 8310 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.130069305220403 (code B ref -1); Mon, 21 Mar 2011 07:38:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 21 Mar 2011 07:37:32 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q1ZgB-0005J2-1F for submit@debbugs.gnu.org; Mon, 21 Mar 2011 03:37:32 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q1Zg9-0005Io-Af for submit@debbugs.gnu.org; Mon, 21 Mar 2011 03:37:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q1Zg3-0004fI-99 for submit@debbugs.gnu.org; Mon, 21 Mar 2011 03:37:24 -0400 Original-Received: from lists.gnu.org ([199.232.76.165]:57878) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q1Zg2-0004fC-A5 for submit@debbugs.gnu.org; Mon, 21 Mar 2011 03:37:23 -0400 Original-Received: from [140.186.70.92] (port=40821 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q1Zfx-00048I-6f for bug-gnu-emacs@gnu.org; Mon, 21 Mar 2011 03:37:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q1Zfs-0004et-KS for bug-gnu-emacs@gnu.org; Mon, 21 Mar 2011 03:37:13 -0400 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:41655) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q1Zfs-0004en-Dy for bug-gnu-emacs@gnu.org; Mon, 21 Mar 2011 03:37:12 -0400 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 1F53539E80E0 for ; Mon, 21 Mar 2011 00:37:10 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JvrmQtZirnSF for ; Mon, 21 Mar 2011 00:37:09 -0700 (PDT) Original-Received: from [192.168.1.10] (pool-71-189-109-235.lsanca.fios.verizon.net [71.189.109.235]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 9EA8E39E80DB for ; Mon, 21 Mar 2011 00:37:09 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Mon, 21 Mar 2011 03:38:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:45219 Archived-At: 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);