GNU bug report logs - #8828
unsigned casts in PTR_BYTE_POS and BUF_PTR_BYTE_POS

Previous Next

Package: emacs;

Reported by: Paul Eggert <eggert <at> cs.ucla.edu>

Date: Thu, 9 Jun 2011 06:55:01 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 8828 in the body.
You can then email your comments to 8828 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#8828; Package emacs. (Thu, 09 Jun 2011 06:55:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Paul Eggert <eggert <at> cs.ucla.edu>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 09 Jun 2011 06:55:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: bug-gnu-emacs <at> gnu.org
Subject: unsigned casts in PTR_BYTE_POS and BUF_PTR_BYTE_POS
Date: Wed, 08 Jun 2011 23:54:36 -0700
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)
 




Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Sat, 31 Dec 2011 08:41:01 GMT) Full text and rfc822 format available.

Notification sent to Paul Eggert <eggert <at> cs.ucla.edu>:
bug acknowledged by developer. (Sat, 31 Dec 2011 08:41:02 GMT) Full text and rfc822 format available.

Message #10 received at 8828-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: 8828-done <at> debbugs.gnu.org
Subject: Re: unsigned casts in PTR_BYTE_POS and BUF_PTR_BYTE_POS
Date: Sat, 31 Dec 2011 00:37:15 -0800
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.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 28 Jan 2012 12:24:02 GMT) Full text and rfc822 format available.

This bug report was last modified 13 years and 150 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.