From: Paul Eggert <eggert@cs.ucla.edu>
To: 8828@debbugs.gnu.org
Subject: bug#8828: unsigned casts in PTR_BYTE_POS and BUF_PTR_BYTE_POS
Date: Wed, 08 Jun 2011 23:54:36 -0700 [thread overview]
Message-ID: <4DF06E2C.3050303@cs.ucla.edu> (raw)
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)
next reply other threads:[~2011-06-09 6:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-09 6:54 Paul Eggert [this message]
2011-12-31 8:37 ` bug#8828: unsigned casts in PTR_BYTE_POS and BUF_PTR_BYTE_POS Paul Eggert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4DF06E2C.3050303@cs.ucla.edu \
--to=eggert@cs.ucla.edu \
--cc=8828@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.