From unknown Mon Jun 23 13:14:13 2025 X-Loop: help-debbugs@gnu.org Subject: bug#8828: unsigned casts in PTR_BYTE_POS and BUF_PTR_BYTE_POS 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: Thu, 09 Jun 2011 06:55:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 8828 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 8828@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.130760250122678 (code B ref -1); Thu, 09 Jun 2011 06:55:01 +0000 Received: (at submit) by debbugs.gnu.org; 9 Jun 2011 06:55:01 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QUZ8v-0005tj-0p for submit@debbugs.gnu.org; Thu, 09 Jun 2011 02:55:01 -0400 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QUZ8s-0005tW-SP for submit@debbugs.gnu.org; Thu, 09 Jun 2011 02:54:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QUZ8m-0008Qp-8z for submit@debbugs.gnu.org; Thu, 09 Jun 2011 02:54:53 -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 ([140.186.70.17]:34950) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QUZ8l-0008QZ-KU for submit@debbugs.gnu.org; Thu, 09 Jun 2011 02:54:51 -0400 Received: from eggs.gnu.org ([140.186.70.92]:53128) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QUZ8j-0005VE-JE for bug-gnu-emacs@gnu.org; Thu, 09 Jun 2011 02:54:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QUZ8h-0008Pv-F9 for bug-gnu-emacs@gnu.org; Thu, 09 Jun 2011 02:54:49 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]:36144) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QUZ8g-0008Np-U1 for bug-gnu-emacs@gnu.org; Thu, 09 Jun 2011 02:54:47 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id EC04739E811D for ; Wed, 8 Jun 2011 23:54:36 -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 lAS6ZJL6aekh for ; Wed, 8 Jun 2011 23:54:36 -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 70AF039E80F0 for ; Wed, 8 Jun 2011 23:54:36 -0700 (PDT) Message-ID: <4DF06E2C.3050303@cs.ucla.edu> Date: Wed, 08 Jun 2011 23:54:36 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110516 Thunderbird/3.1.10 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, 3) X-Received-From: 140.186.70.17 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 (----) Currently, src/buffer.h's macros PTR_BYTE_POS and BUF_PTR_BYTE_POS both cast subexpressions to 'unsigned'. This can't be right on a 64-bit host, since the subexpressions might exceed 2**32 if the buffer is large, and their values shouldn't be truncated to 32 bits. I can't see why the cast to 'unsigned' is there at all, even on a 32-bit host; unless I'm missing something the values being compared are always nonnegative. So I'd like to install the following patch into the trunk, after some testing. === modified file 'src/buffer.h' --- src/buffer.h 2011-06-06 19:43:39 +0000 +++ src/buffer.h 2011-06-09 04:04:41 +0000 @@ -337,7 +337,7 @@ #define PTR_BYTE_POS(ptr) \ ((ptr) - (current_buffer)->text->beg \ - - (ptr - (current_buffer)->text->beg <= (unsigned) (GPT_BYTE - BEG_BYTE) ? 0 : GAP_SIZE) \ + - (ptr - (current_buffer)->text->beg <= GPT_BYTE - BEG_BYTE ? 0 : GAP_SIZE) \ + BEG_BYTE) /* Return character at byte position POS. */ @@ -396,7 +396,7 @@ #define BUF_PTR_BYTE_POS(buf, ptr) \ ((ptr) - (buf)->text->beg \ - - (ptr - (buf)->text->beg <= (unsigned) (BUF_GPT_BYTE ((buf)) - BEG_BYTE)\ + - (ptr - (buf)->text->beg <= BUF_GPT_BYTE ((buf)) - BEG_BYTE \ ? 0 : BUF_GAP_SIZE ((buf))) \ + BEG_BYTE) From unknown Mon Jun 23 13:14:13 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#8828: closed (Re: unsigned casts in PTR_BYTE_POS and BUF_PTR_BYTE_POS) Message-ID: References: <4EFEC9BB.4040105@cs.ucla.edu> <4DF06E2C.3050303@cs.ucla.edu> X-Gnu-PR-Message: they-closed 8828 X-Gnu-PR-Package: emacs Reply-To: 8828@debbugs.gnu.org Date: Sat, 31 Dec 2011 08:41:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1325320862-32039-1" This is a multi-part message in MIME format... ------------=_1325320862-32039-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #8828: unsigned casts in PTR_BYTE_POS and BUF_PTR_BYTE_POS 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 8828@debbugs.gnu.org. --=20 8828: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D8828 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1325320862-32039-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 8828-done) by debbugs.gnu.org; 31 Dec 2011 08:40:20 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RguUG-0008Jo-34 for submit@debbugs.gnu.org; Sat, 31 Dec 2011 03:40:20 -0500 Received: from smtp.cs.ucla.edu ([131.179.128.62]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RguUD-0008Jf-PP for 8828-done@debbugs.gnu.org; Sat, 31 Dec 2011 03:40:18 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 81341A60004 for <8828-done@debbugs.gnu.org>; Sat, 31 Dec 2011 00:37:16 -0800 (PST) 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 mKRY-U3inJzn for <8828-done@debbugs.gnu.org>; Sat, 31 Dec 2011 00:37:16 -0800 (PST) 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 341B8A60001 for <8828-done@debbugs.gnu.org>; Sat, 31 Dec 2011 00:37:16 -0800 (PST) Message-ID: <4EFEC9BB.4040105@cs.ucla.edu> Date: Sat, 31 Dec 2011 00:37:15 -0800 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20111124 Thunderbird/8.0 MIME-Version: 1.0 To: 8828-done@debbugs.gnu.org Subject: Re: unsigned casts in PTR_BYTE_POS and BUF_PTR_BYTE_POS Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Score: -2.9 (--) X-Debbugs-Envelope-To: 8828-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: -2.9 (--) This bug was fixed in bzr 104599 in the trunk, dated 2011-06-15. I forgot to close it then but am closing it now. ------------=_1325320862-32039-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 9 Jun 2011 06:55:01 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QUZ8v-0005tj-0p for submit@debbugs.gnu.org; Thu, 09 Jun 2011 02:55:01 -0400 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QUZ8s-0005tW-SP for submit@debbugs.gnu.org; Thu, 09 Jun 2011 02:54:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QUZ8m-0008Qp-8z for submit@debbugs.gnu.org; Thu, 09 Jun 2011 02:54:53 -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 ([140.186.70.17]:34950) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QUZ8l-0008QZ-KU for submit@debbugs.gnu.org; Thu, 09 Jun 2011 02:54:51 -0400 Received: from eggs.gnu.org ([140.186.70.92]:53128) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QUZ8j-0005VE-JE for bug-gnu-emacs@gnu.org; Thu, 09 Jun 2011 02:54:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QUZ8h-0008Pv-F9 for bug-gnu-emacs@gnu.org; Thu, 09 Jun 2011 02:54:49 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]:36144) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QUZ8g-0008Np-U1 for bug-gnu-emacs@gnu.org; Thu, 09 Jun 2011 02:54:47 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id EC04739E811D for ; Wed, 8 Jun 2011 23:54:36 -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 lAS6ZJL6aekh for ; Wed, 8 Jun 2011 23:54:36 -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 70AF039E80F0 for ; Wed, 8 Jun 2011 23:54:36 -0700 (PDT) Message-ID: <4DF06E2C.3050303@cs.ucla.edu> Date: Wed, 08 Jun 2011 23:54:36 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110516 Thunderbird/3.1.10 MIME-Version: 1.0 To: bug-gnu-emacs@gnu.org Subject: unsigned casts in PTR_BYTE_POS and BUF_PTR_BYTE_POS 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, 3) X-Received-From: 140.186.70.17 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 (----) Currently, src/buffer.h's macros PTR_BYTE_POS and BUF_PTR_BYTE_POS both cast subexpressions to 'unsigned'. This can't be right on a 64-bit host, since the subexpressions might exceed 2**32 if the buffer is large, and their values shouldn't be truncated to 32 bits. I can't see why the cast to 'unsigned' is there at all, even on a 32-bit host; unless I'm missing something the values being compared are always nonnegative. So I'd like to install the following patch into the trunk, after some testing. === modified file 'src/buffer.h' --- src/buffer.h 2011-06-06 19:43:39 +0000 +++ src/buffer.h 2011-06-09 04:04:41 +0000 @@ -337,7 +337,7 @@ #define PTR_BYTE_POS(ptr) \ ((ptr) - (current_buffer)->text->beg \ - - (ptr - (current_buffer)->text->beg <= (unsigned) (GPT_BYTE - BEG_BYTE) ? 0 : GAP_SIZE) \ + - (ptr - (current_buffer)->text->beg <= GPT_BYTE - BEG_BYTE ? 0 : GAP_SIZE) \ + BEG_BYTE) /* Return character at byte position POS. */ @@ -396,7 +396,7 @@ #define BUF_PTR_BYTE_POS(buf, ptr) \ ((ptr) - (buf)->text->beg \ - - (ptr - (buf)->text->beg <= (unsigned) (BUF_GPT_BYTE ((buf)) - BEG_BYTE)\ + - (ptr - (buf)->text->beg <= BUF_GPT_BYTE ((buf)) - BEG_BYTE \ ? 0 : BUF_GAP_SIZE ((buf))) \ + BEG_BYTE) ------------=_1325320862-32039-1--