From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs 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 Message-ID: <83mvzzmy9a.fsf@gnu.org> References: <85fv5za8vv.fsf@iznogoud.viz> <83vbevsctb.fsf@gnu.org> <85oakmxn4i.fsf@iznogoud.viz> <85k2v3veg7.fsf@iznogoud.viz> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1434471026 1543 80.91.229.3 (16 Jun 2015 16:10:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 16 Jun 2015 16:10:26 +0000 (UTC) Cc: 20783@debbugs.gnu.org To: Wolfgang Jenkner Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jun 16 18:10:16 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Z4tRH-0006Bz-Dp for geb-bug-gnu-emacs@m.gmane.org; Tue, 16 Jun 2015 18:10:15 +0200 Original-Received: from localhost ([::1]:41318 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4tRG-0001wQ-Ox for geb-bug-gnu-emacs@m.gmane.org; Tue, 16 Jun 2015 12:10:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50703) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4tRC-0001w6-HO for bug-gnu-emacs@gnu.org; Tue, 16 Jun 2015 12:10:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z4tR6-000325-S8 for bug-gnu-emacs@gnu.org; Tue, 16 Jun 2015 12:10:10 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:41570) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4tR6-00031S-PZ for bug-gnu-emacs@gnu.org; Tue, 16 Jun 2015 12:10:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Z4tR5-0006IX-Vq for bug-gnu-emacs@gnu.org; Tue, 16 Jun 2015 12:10:04 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 16 Jun 2015 16:10:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20783 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 20783-submit@debbugs.gnu.org id=B20783.143447096024155 (code B ref 20783); Tue, 16 Jun 2015 16:10:03 +0000 Original-Received: (at 20783) by debbugs.gnu.org; 16 Jun 2015 16:09:20 +0000 Original-Received: from localhost ([127.0.0.1]:56030 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Z4tQN-0006HW-Oi for submit@debbugs.gnu.org; Tue, 16 Jun 2015 12:09:20 -0400 Original-Received: from mtaout20.012.net.il ([80.179.55.166]:54133) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Z4tQK-0006HI-SS for 20783@debbugs.gnu.org; Tue, 16 Jun 2015 12:09:18 -0400 Original-Received: from conversion-daemon.a-mtaout20.012.net.il by a-mtaout20.012.net.il (HyperSendmail v2007.08) id <0NQ100100OKZ8100@a-mtaout20.012.net.il> for 20783@debbugs.gnu.org; Tue, 16 Jun 2015 19:09:10 +0300 (IDT) Original-Received: from HOME-C4E4A596F7 ([87.69.4.28]) by a-mtaout20.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0NQ1001R3OV10UA0@a-mtaout20.012.net.il>; Tue, 16 Jun 2015 19:09:01 +0300 (IDT) In-reply-to: <85k2v3veg7.fsf@iznogoud.viz> X-012-Sender: halo1@inter.net.il X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 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.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:103995 Archived-At: > From: Wolfgang Jenkner > 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.