From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#41125: 28.0.50; Fwindow_text_pixel_size uses FETCH_CHAR (charpos) Date: Thu, 07 May 2020 16:36:19 +0300 Message-ID: <83mu6jkgto.fsf@gnu.org> References: Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="2714"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 41125@debbugs.gnu.org To: Pip Cet , martin rudalics Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu May 07 15:37:11 2020 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 1jWgi7-0000bN-8V for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 07 May 2020 15:37:11 +0200 Original-Received: from localhost ([::1]:53936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jWgi5-00054s-VN for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 07 May 2020 09:37:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60230) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWghy-00054l-Cq for bug-gnu-emacs@gnu.org; Thu, 07 May 2020 09:37:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:59110) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jWghy-0001Bb-42 for bug-gnu-emacs@gnu.org; Thu, 07 May 2020 09:37:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jWghx-0007jz-Up for bug-gnu-emacs@gnu.org; Thu, 07 May 2020 09:37:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 07 May 2020 13:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41125 X-GNU-PR-Package: emacs Original-Received: via spool by 41125-submit@debbugs.gnu.org id=B41125.158885860429726 (code B ref 41125); Thu, 07 May 2020 13:37:01 +0000 Original-Received: (at 41125) by debbugs.gnu.org; 7 May 2020 13:36:44 +0000 Original-Received: from localhost ([127.0.0.1]:42423 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jWghf-0007jO-PH for submit@debbugs.gnu.org; Thu, 07 May 2020 09:36:44 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:57168) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jWghe-0007jD-Lm for 41125@debbugs.gnu.org; Thu, 07 May 2020 09:36:43 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:50225) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jWghX-0000wE-2d; Thu, 07 May 2020 09:36:37 -0400 Original-Received: from [176.228.60.248] (port=1836 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1jWghW-0000Nq-FZ; Thu, 07 May 2020 09:36:34 -0400 In-Reply-To: (message from Pip Cet on Thu, 7 May 2020 11:55:07 +0000) 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:179883 Archived-At: > From: Pip Cet > Date: Thu, 7 May 2020 11:55:07 +0000 > > Fwindow_text_pixel_size contains this code: > > start = pos = BEGV; > while ((pos++ < ZV) && (c = FETCH_CHAR (pos)) > && (c == ' ' || c == '\t' || c == '\n' || c == '\r')) > start = pos; > while ((pos-- > BEGV) && (c = FETCH_CHAR (pos)) && (c == ' ' || > c == '\t')) > start = pos; > > which cannot possibly be correct: FETCH_CHAR takes a byte position, > not a character position, but BEGV and ZV are measured in characters. Ouch! Thanks. Does the patch below look good? > (I'm familiarizing myself with the xdisp.c code, partly by replacing > bytepos/charpos pairs of variables with a combined pos_t type > variable. I think that's a good idea partly because it would prevent > precisely this kind of bug.) It might be good for a development build, but not for production: walking the buffer must be very efficient. diff --git a/src/xdisp.c b/src/xdisp.c index 19f4f32..c15dd47 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -10442,7 +10442,7 @@ height (excluding the height of the mode- or header-line, if any) that struct buffer *b; struct it it; struct buffer *old_b = NULL; - ptrdiff_t start, end, pos; + ptrdiff_t start, end, bpos; struct text_pos startp; void *itdata = NULL; int c, max_x = 0, max_y = 0, x = 0, y = 0; @@ -10457,32 +10457,56 @@ height (excluding the height of the mode- or header-line, if any) that } if (NILP (from)) - start = BEGV; + { + start = BEGV; + bpos = BEGV_BYTE; + } else if (EQ (from, Qt)) { - start = pos = BEGV; - while ((pos++ < ZV) && (c = FETCH_CHAR (pos)) - && (c == ' ' || c == '\t' || c == '\n' || c == '\r')) - start = pos; - while ((pos-- > BEGV) && (c = FETCH_CHAR (pos)) && (c == ' ' || c == '\t')) - start = pos; + start = BEGV; + bpos = BEGV_BYTE; + while (bpos < ZV_BYTE) + { + FETCH_CHAR_ADVANCE (c, start, bpos); + if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r')) + break; + } + while (bpos > BEGV_BYTE) + { + DEC_BOTH (start, bpos); + c = FETCH_CHAR (bpos); + if (!(c == ' ' || c == '\t')) + break; + } } else { CHECK_FIXNUM_COERCE_MARKER (from); start = min (max (XFIXNUM (from), BEGV), ZV); + bpos = CHAR_TO_BYTE (start); } + SET_TEXT_POS (startp, start, bpos); + if (NILP (to)) end = ZV; else if (EQ (to, Qt)) { - end = pos = ZV; - while ((pos-- > BEGV) && (c = FETCH_CHAR (pos)) - && (c == ' ' || c == '\t' || c == '\n' || c == '\r')) - end = pos; - while ((pos++ < ZV) && (c = FETCH_CHAR (pos)) && (c == ' ' || c == '\t')) - end = pos; + end = ZV; + bpos = ZV_BYTE; + while (bpos > BEGV_BYTE) + { + DEC_BOTH (end, bpos); + c = FETCH_CHAR (bpos); + if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r')) + break; + } + while (bpos < ZV_BYTE) + { + FETCH_CHAR_ADVANCE (c, end, bpos); + if (!(c == ' ' || c == '\t')) + break; + } } else { @@ -10499,7 +10523,6 @@ height (excluding the height of the mode- or header-line, if any) that max_y = XFIXNUM (y_limit); itdata = bidi_shelve_cache (); - SET_TEXT_POS (startp, start, CHAR_TO_BYTE (start)); start_display (&it, w, startp); /* It makes no sense to measure dimensions of region of text that crosses the point where bidi reordering changes scan direction.