From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs 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 Message-ID: <87fskfqpvh.fsf@yahoo.com> References: Reply-To: Po Lu Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30974"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.91 (gnu/linux) Cc: 55847@debbugs.gnu.org To: Antoine Kalmbach Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jun 08 15:20:22 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nyvbh-0007kd-C3 for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 08 Jun 2022 15:20:21 +0200 Original-Received: from localhost ([::1]:59920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyvbg-0005q5-EU for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 08 Jun 2022 09:20:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34480) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyvBG-0005nG-Gd for bug-gnu-emacs@gnu.org; Wed, 08 Jun 2022 08:53:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48841) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nyvBF-0000wx-UV for bug-gnu-emacs@gnu.org; Wed, 08 Jun 2022 08:53:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nyvBF-0000d5-Rl for bug-gnu-emacs@gnu.org; Wed, 08 Jun 2022 08:53:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Po Lu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 08 Jun 2022 12:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55847 X-GNU-PR-Package: emacs Original-Received: via spool by 55847-submit@debbugs.gnu.org id=B55847.16546927582389 (code B ref 55847); Wed, 08 Jun 2022 12:53:01 +0000 Original-Received: (at 55847) by debbugs.gnu.org; 8 Jun 2022 12:52:38 +0000 Original-Received: from localhost ([127.0.0.1]:42738 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nyvAs-0000cT-IH for submit@debbugs.gnu.org; Wed, 08 Jun 2022 08:52:38 -0400 Original-Received: from sonic301-31.consmr.mail.ne1.yahoo.com ([66.163.184.200]:40218) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nyvAp-0000cG-VS for 55847@debbugs.gnu.org; Wed, 08 Jun 2022 08:52:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1654692750; bh=VZrYiFUwzma/ewjCHlg40skl5ENFSsmbDK5+MJRjvX0=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From:Subject:Reply-To; b=AqC88R4OzKEgr1ysRR/QD4XxQ0oe9A0TjZKhsHQNQIhphd3QYC6eLoHa+KHF+clEpSQZpG5mrIb6fmTGJYUO6S/DU8izKfwqHuQ0Sm55C2PeQ26qmSD/FwkyVPecJwfAkocvIS4cbv/jIrv8P10bFBYwFJWwMNOS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zaFZWW6bDQQjVu2z7ZM2RtOFQGOKzFdYl53S5IxoKClkW5Uby9lWmPXbUqQao5V zx6VCq_sDcTG0IB.y_IfNegBd.KZRJ75f5Yv1IfOiVNmuWWRTqletlcKC5.g5zFfeaAsI6uJ7Sn9 Vt42R8R9gXWxg_KvD48vLAyeDQMuLVwNsfPTVrifXniKlQV6lgKaLJOvLOIx0yf326LrFfv5mNrZ aWbyPdAm4S3VCWotUMgzzvkpIKhd7z0W0KoU3QJqA39PHDlyPZleH3qas75ZBmkeswGKOQlfYZ3L vHCBTDkyIs4aHPWLqssvjcL3l9GYHT0d4FDCdlYBsR3SYsKEN2o1BpYG2sccyN82W4v8n0bKMRbN iMSIf5ck.WlGxK5PZl_Q8D9GXixd0agoii72GteJ1qF3RQglVN9Y2cEFr62srUKXUT0g6ZN39h72 vf5AxJw.UJnpMVjLWbh4ZAdkD1SMxTNPahslqDDcGE X-Sonic-MF: Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic301.consmr.mail.ne1.yahoo.com with HTTP; Wed, 8 Jun 2022 12:52:30 +0000 Original-Received: by hermes--canary-production-sg3-5f7658c994-r59gj (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 21b57ba88b1a57bcaf533f03985e92cf; Wed, 08 Jun 2022 12:52:23 +0000 (UTC) In-Reply-To: (Antoine Kalmbach's message of "Wed, 08 Jun 2022 14:44:10 +0300") X-Mailer: WebService/1.1.20280 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:233970 Archived-At: Antoine Kalmbach 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.