unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Antoine Kalmbach <ane@iki.fi>
Cc: 55847@debbugs.gnu.org
Subject: bug#55847: 29.0.50; line-number-at-pos ignores absolute parameter when checking position range
Date: Wed, 08 Jun 2022 20:52:18 +0800	[thread overview]
Message-ID: <87fskfqpvh.fsf@yahoo.com> (raw)
In-Reply-To: <lyczfjcrcl.fsf@iki.fi> (Antoine Kalmbach's message of "Wed, 08 Jun 2022 14:44:10 +0300")

Antoine Kalmbach <ane@iki.fi> writes:

> When working with a narrowed buffer, line-number-at-pos complains
> that the passed position parameter is out of range.
>
> I believe this occurs because in fns.c there is check as follows:
>
>    if (pos < BEGV || pos > ZV)
>
> This works just fine when the buffer isn't narrowed, but narrowing
> affects BEGV. Suppose the buffer is narrowed, and you want to get the
> line number for position x where x is before where the current narrowing
> begins, passing (line-number-at-pos x t) now reports an error

That's intentional behavior.  Very rarely is code allowed to access
buffer contents outside the accessible portion of the buffer, and
line-number-at-pos is not such a piece of code.

> because the correct thing to check is BEGV_BYTE, not BEGV.
> I think the change is as simple as checking pos < start, instead of pos
> < BEGV.
>
> The easiest way to reproduce is to make a buffer, narrow to a part of
> it, then evaluate (line-number-at-pos x t) where x is smaller than the
> absolute position of the narrowing, i.e. X < BEGV, but on the other hand
> x >= BEGV_BYTE.

BEGV_BYTE is the byte position of BEGV, but narrow-to-region and
line-number-at-pos operate on character positions, so comparing pos with
BEGV_BYTE doesn't make sense.  We don't want to allow code to access
buffer contents outside the accessible region, and besides, which lines
would they be on?  They are not visible, and there is no "starting
point" to calculate from.





  reply	other threads:[~2022-06-08 12:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-08 11:44 bug#55847: 29.0.50; line-number-at-pos ignores absolute parameter when checking position range Antoine Kalmbach
2022-06-08 12:52 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-06-08 14:02 ` Eli Zaretskii
2022-06-09  7:44   ` Antoine Kalmbach
2022-06-09 10:46     ` Lars Ingebrigtsen
2022-06-09 11:19       ` Antoine Kalmbach
2022-06-09 12:43         ` Lars Ingebrigtsen

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=87fskfqpvh.fsf@yahoo.com \
    --to=bug-gnu-emacs@gnu.org \
    --cc=55847@debbugs.gnu.org \
    --cc=ane@iki.fi \
    --cc=luangruo@yahoo.com \
    /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).