From unknown Tue Aug 19 04:06:26 2025 X-Loop: help-debbugs@gnu.org Subject: bug#8310: update-game-score -r logic broken with MAX_SCORES 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: To: 8310@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.130069305220403 (code B ref -1); Mon, 21 Mar 2011 07:38:02 +0000 Received: (at submit) by debbugs.gnu.org; 21 Mar 2011 07:37:32 +0000 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 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 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 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_RP_MATCHES_RCVD autolearn=unavailable version=3.3.1 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 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 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 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 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 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) 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) Message-ID: <4D870025.8010702@cs.ucla.edu> Date: Mon, 21 Mar 2011 00:37:09 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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-Received-From: 199.232.76.165 X-Spam-Score: -4.7 (----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -4.7 (----) 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); From unknown Tue Aug 19 04:06:26 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.427 (Entity 5.427) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Paul Eggert Subject: bug#8310: closed (fix merged to trunk) Message-ID: References: <4D8A6EF6.6010006@cs.ucla.edu> <4D870025.8010702@cs.ucla.edu> X-Gnu-PR-Message: they-closed 8310 X-Gnu-PR-Package: emacs Reply-To: 8310@debbugs.gnu.org Date: Wed, 23 Mar 2011 22:07:13 +0000 Content-Type: multipart/mixed; boundary="----------=_1300918033-30530-1" This is a multi-part message in MIME format... ------------=_1300918033-30530-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #8310: update-game-score -r logic broken with MAX_SCORES which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 8310@debbugs.gnu.org. --=20 8310: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D8310 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1300918033-30530-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 8310-done) by debbugs.gnu.org; 23 Mar 2011 22:07:03 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q2WCj-0007v7-Dn for submit@debbugs.gnu.org; Wed, 23 Mar 2011 18:07:01 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q2WCb-0007uA-KO; Wed, 23 Mar 2011 18:06:54 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 7955339E80F5; Wed, 23 Mar 2011 15:06:47 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu 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 DCQ03AM5OnEs; Wed, 23 Mar 2011 15:06:47 -0700 (PDT) Received: from [131.179.64.200] (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 2047839E80B1; Wed, 23 Mar 2011 15:06:47 -0700 (PDT) Message-ID: <4D8A6EF6.6010006@cs.ucla.edu> Date: Wed, 23 Mar 2011 15:06:46 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.15) Gecko/20110307 Fedora/3.1.9-0.39.b3pre.fc14 Thunderbird/3.1.9 MIME-Version: 1.0 To: 8310-done@debbugs.gnu.org, 8318-done@debbugs.gnu.org, 8306-done@debbugs.gnu.org, 8303-done@debbugs.gnu.org, 8277-done@debbugs.gnu.org, 8298-done@debbugs.gnu.org, 8290-done@debbugs.gnu.org, 8278-done@debbugs.gnu.org Subject: fix merged to trunk Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam-Score: -3.3 (---) X-Debbugs-Envelope-To: 8310-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.2 (---) I committed a fix to the trunk for this, as part of a recent merge (bzr 103721). ------------=_1300918033-30530-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 21 Mar 2011 07:37:32 +0000 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 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 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 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_RP_MATCHES_RCVD autolearn=unavailable version=3.3.1 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 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 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 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 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 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) 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) Message-ID: <4D870025.8010702@cs.ucla.edu> Date: Mon, 21 Mar 2011 00:37:09 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 MIME-Version: 1.0 To: bug-gnu-emacs@gnu.org Subject: update-game-score -r logic broken with MAX_SCORES Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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-Received-From: 199.232.76.165 X-Spam-Score: -4.7 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -4.7 (----) 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); ------------=_1300918033-30530-1--