unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Pip Cet <pipcet@gmail.com>
To: Stefan Kangas <stefan@marxist.se>
Cc: 41520@debbugs.gnu.org
Subject: bug#41520: 28.0.50; Crash in character.h due to assertion error
Date: Mon, 25 May 2020 07:41:54 +0000	[thread overview]
Message-ID: <CAOqdjBebS5JY109xSxnWghdPTcpghuKLRi1DXJVG+eqwEVb1aw@mail.gmail.com> (raw)
In-Reply-To: <CAOqdjBe5CG5A7MGQ0hY7BZDi+EAwFczJ0MYxTPcxmVjxS_=J8Q@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 619 bytes --]

On Mon, May 25, 2020 at 7:28 AM Pip Cet <pipcet@gmail.com> wrote:
> On Mon, May 25, 2020 at 7:06 AM Stefan Kangas <stefan@marxist.se> wrote:
> There's at least one other place that has the same error, so I'll grep
> some more before sending a patch.

Patch attached (it compiles, but I haven't tested it thoroughly). This
should fix two bugs in xdisp.c and a bug in Fend_of_line.

All of these bugs were silently fixed by my pos_t conversion.

At the very least, FETCH_CHAR should be renamed so it's clear that the
right way to use it is FETCH_CHAR (bytepos), not FETCH_CHAR (charpos).
I suggest FETCH_CHAR_AT_BYTEPOS.

[-- Attachment #2: 0001-Fix-assertion-errors-caused-by-bytepos-charpos-confu.patch --]
[-- Type: text/x-patch, Size: 2070 bytes --]

From 460ddd6c40940610548c74efbd3da9fa8b170f71 Mon Sep 17 00:00:00 2001
From: Pip Cet <pipcet@gmail.com>
Date: Mon, 25 May 2020 07:35:28 +0000
Subject: [PATCH] Fix assertion errors caused by bytepos/charpos confusion

* src/xdisp.c (Fbidi_find_overridden_directionality): Use
FETCH_BYTE, not FETCH_CHAR, for a decremented byte position.
(get_visually_first_element): Ditto.

* src/cmds.c (Fend_of_line): Use byte positions for FETCH_CHAR,
not char positions.
---
 src/cmds.c  | 4 ++--
 src/xdisp.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/cmds.c b/src/cmds.c
index 9f96f210b9..d198bafc17 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -194,7 +194,7 @@ DEFUN ("end-of-line", Fend_of_line, Send_of_line, 0, 1, "^p",
       SET_PT (newpos);
 
       if (PT > newpos
-	  && FETCH_CHAR (PT - 1) == '\n')
+	  && FETCH_CHAR (PT_BYTE - 1) == '\n')
 	{
 	  /* If we skipped over a newline that follows
 	     an invisible intangible run,
@@ -205,7 +205,7 @@ DEFUN ("end-of-line", Fend_of_line, Send_of_line, 0, 1, "^p",
 	  break;
 	}
       else if (PT > newpos && PT < ZV
-	       && FETCH_CHAR (PT) != '\n')
+	       && FETCH_CHAR (PT_BYTE) != '\n')
 	/* If we skipped something intangible
 	   and now we're not really at eol,
 	   keep going.  */
diff --git a/src/xdisp.c b/src/xdisp.c
index cf15f579b5..00c526874c 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -8290,7 +8290,7 @@ get_visually_first_element (struct it *it)
     }
   else if (it->bidi_it.charpos == bob
 	   || (!string_p
-	       && (FETCH_CHAR (it->bidi_it.bytepos - 1) == '\n'
+	       && (FETCH_BYTE (it->bidi_it.bytepos - 1) == '\n'
 		   || FETCH_CHAR (it->bidi_it.bytepos) == '\n')))
     {
       /* If we are at the beginning of a line/string, we can produce
@@ -24182,7 +24182,7 @@ DEFUN ("bidi-find-overridden-directionality",
 	  itb.charpos = BEGV;
 	  itb.bytepos = BEGV_BYTE;
 	}
-      else if (FETCH_CHAR (from_bpos - 1) == '\n')
+      else if (FETCH_BYTE (from_bpos - 1) == '\n')
 	{
 	  itb.charpos = from_pos;
 	  itb.bytepos = from_bpos;
-- 
2.27.0.rc0


  reply	other threads:[~2020-05-25  7:41 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-25  7:05 bug#41520: 28.0.50; Crash in character.h due to assertion error Stefan Kangas
2020-05-25  7:28 ` Pip Cet
2020-05-25  7:41   ` Pip Cet [this message]
2020-05-25 14:18   ` Eli Zaretskii
2020-05-25 14:30     ` Pip Cet
2020-05-25 15:07       ` Eli Zaretskii
2020-05-25 15:16         ` Pip Cet
2020-05-25 16:09           ` Eli Zaretskii
2020-05-25 17:54             ` Pip Cet
2020-05-25 19:30               ` Eli Zaretskii
2020-05-25 20:39                 ` Pip Cet
2020-05-26 16:17                   ` Eli Zaretskii
2020-09-27 14:36         ` Lars Ingebrigtsen
2020-09-27 15:15           ` Eli Zaretskii
2020-09-27 15:42             ` Lars Ingebrigtsen
2020-09-27 16:00               ` Eli Zaretskii

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=CAOqdjBebS5JY109xSxnWghdPTcpghuKLRi1DXJVG+eqwEVb1aw@mail.gmail.com \
    --to=pipcet@gmail.com \
    --cc=41520@debbugs.gnu.org \
    --cc=stefan@marxist.se \
    /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).