Subject: bug#8828: closed (Re: unsigned casts in PTR_BYTE_POS and BUF_PTR_BYTE_POS)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 31 Dec 2011 08:41:02 +0000

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 [email-masked].

-- 
8828: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8828
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: unsigned casts in PTR_BYTE_POS and BUF_PTR_BYTE_POS
From: Paul Eggert <[email-masked]>
To: [email-masked]
Date: Sat, 31 Dec 2011 00:37:15 -0800
List-Id: <debbugs-submit.debbugs.gnu.org>

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.

Subject: unsigned casts in PTR_BYTE_POS and BUF_PTR_BYTE_POS
From: Paul Eggert <[email-masked]>
To: [email-masked]
Date: Wed, 08 Jun 2011 23:54:36 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

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)