all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Wolfgang Jenkner <wjenkner@inode.at>
Cc: 20783@debbugs.gnu.org
Subject: bug#20783: 25.0.50; [PATCH] byte-to-position has internal off-by-one bug
Date: Tue, 16 Jun 2015 19:08:49 +0300	[thread overview]
Message-ID: <83mvzzmy9a.fsf@gnu.org> (raw)
In-Reply-To: <85k2v3veg7.fsf@iznogoud.viz>

> From: Wolfgang Jenkner <wjenkner@inode.at>
> Cc: 20783@debbugs.gnu.org
> Date: Tue, 16 Jun 2015 17:40:38 +0200
> 
> +      while (!CHAR_HEAD_P (*chp))
> +	{
> +	  pos_byte--;
> +	  /* There's no buffer gap in the middle of a character.  */
> +	  chp--;
> +	}

Thanks, but I'd prefer we didn't have code that manipulated pointers
to buffer text directly.  E.g., if we ever have some kind of
multi-threading, or even if at some point someone adds a non-trivial
function call to this loop, this code will be a subtle bug waiting to
bite.  It's fundamentally not safe to do this, and not only due to the
gap considerations, but also because in general BEG_ADDR might change
under certain circumstances behind your back.  (Buffer text and string
data are implemented with double indirection for good reasons.)

For some very tight loops, it might be justified to take these
shortcuts (with WARNING COMMENTS CRYING BLOODY MURDER all around), but
this function doesn't belong to those cases.

So I prefer the previous variant, even though it will lose that
benchmark.





  reply	other threads:[~2015-06-16 16:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-10 15:13 bug#20783: 25.0.50; [PATCH] byte-to-position has internal off-by-one bug Wolfgang Jenkner
2015-06-10 17:17 ` Eli Zaretskii
2015-06-11 15:24   ` Wolfgang Jenkner
2015-06-11 16:04     ` Eli Zaretskii
2015-06-11 16:41       ` Wolfgang Jenkner
2015-06-11 19:08         ` Eli Zaretskii
2015-06-17 12:19       ` Wolfgang Jenkner
2015-06-17 16:57         ` Eli Zaretskii
2015-06-16 15:40     ` Wolfgang Jenkner
2015-06-16 16:08       ` Eli Zaretskii [this message]
2015-06-16 16:31         ` Wolfgang Jenkner

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=83mvzzmy9a.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=20783@debbugs.gnu.org \
    --cc=wjenkner@inode.at \
    /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.