unofficial mirror of bug-gnu-emacs@gnu.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: Wed, 10 Jun 2015 20:17:20 +0300	[thread overview]
Message-ID: <83vbevsctb.fsf@gnu.org> (raw)
In-Reply-To: <85fv5za8vv.fsf@iznogoud.viz>

> From: Wolfgang Jenkner <wjenkner@inode.at>
> Date: Wed, 10 Jun 2015 17:13:30 +0200
> 
> Here's a test case for the bug:
> 
> (with-temp-buffer
>   (insert "éé")
>   (let ((i 1) pos res)
>     (while (setq pos (byte-to-position i))
>       (push pos res)
>       (setq i (1+ i)))
>     (nreverse res)))
> 
> => (1 2 2 2 3)
> 
> while the correct result is
> 
> => (1 1 2 2 3)
> 
> I found that this bug had been noticed before in
> 
> http://stackoverflow.com/questions/17588117/emacs-byte-to-position-function-is-not-consistent-with-document
> 
> Here's a patch.  The fix may look a bit clumsy but it's actually meant
> to avoid pessimizing the presumably common case where the initial
> bytepos is at a character boundary.

Wouldn't it be better to handle this use case in Fbyte_to_position?
The BYTE_TO_CHAR macro is called an awful lot in the Emacs innermost
loops, and it's _always_ called with a byte position that's on a
character boundary.  So punishing all that code with even a single
comparison, for the benefit of a use case whose importance is unclear
to me is not necessarily TRT.

Thanks.





  reply	other threads:[~2015-06-10 17:17 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 [this message]
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
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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83vbevsctb.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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).