Subject: Re: bug#41520: 28.0.50; Crash in character.h due to assertion error

From: Lars Ingebrigtsen <[email-masked]>
Date: Sun, 27 Sep 2020 16:36:21 +0200

Eli Zaretskii <[email-masked]> writes:

>> I'm attaching a patch with a few more cases. I don't have a strong
>> preference for either FETCH_BYTE or FETCH_CHAR where both will do, but
>> we should be consistent.
>
> I'm okay with those additional changes, but let's install them on
> master, as they are a cleanup, not a bug.

Pip's patch from May no longer applies cleanly, so I've respun it for
the trunk now.

Does this still look OK?

diff --git a/src/cmds.c b/src/cmds.c
index 90526612b7..c29cf00dad 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -390,7 +390,7 @@ internal_self_insert (int c, EMACS_INT n)
 		     by spaces so that the remaining text won't move.  */
 		  ptrdiff_t actual = PT_BYTE;
 		  actual -= prev_char_len (actual);
-		  if (FETCH_CHAR (actual) == '\t')
+		  if (FETCH_BYTE (actual) == '\t')
 		    /* Rather than add spaces, let's just keep the tab. */
 		    chars_to_delete--;
 		  else
diff --git a/src/syntax.c b/src/syntax.c
index 066972e6d8..cbef61dfbe 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -731,7 +731,6 @@ back_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop,
     {
       rarely_quit (++quit_count);
 
-      ptrdiff_t temp_byte;
       int prev_syntax;
       bool com2start, com2end, comstart;
 
@@ -882,8 +881,7 @@ back_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop,
 	  if (open_paren_in_column_0_is_defun_start
               && NILP (Vcomment_use_syntax_ppss)
 	      && (from == stop
-		  || (temp_byte = dec_bytepos (from_byte),
-		      FETCH_CHAR (temp_byte) == '\n')))
+		  || (FETCH_BYTE (from_byte - 1) == '\n')))
 	    {
 	      defun_start = from;
 	      defun_start_byte = from_byte;
diff --git a/src/xdisp.c b/src/xdisp.c
index 3d40878be6..ecd23e0d0f 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -10619,7 +10619,7 @@ DEFUN ("window-text-pixel-size", Fwindow_text_pixel_size, Swindow_text_pixel_siz
       while (bpos > BEGV_BYTE)
 	{
 	  dec_both (&start, &bpos);
-	  c = FETCH_CHAR (bpos);
+	  c = FETCH_BYTE (bpos);
 	  if (!(c == ' ' || c == '\t'))
 	    break;
 	}
@@ -10641,7 +10641,7 @@ DEFUN ("window-text-pixel-size", Fwindow_text_pixel_size, Swindow_text_pixel_siz
       while (bpos > BEGV_BYTE)
 	{
 	  dec_both (&end, &bpos);
-	  c = FETCH_CHAR (bpos);
+	  c = FETCH_BYTE (bpos);
 	  if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r'))
 	    break;
 	}
@@ -22277,7 +22277,7 @@ trailing_whitespace_p (ptrdiff_t charpos)
   int c = 0;
 
   while (bytepos < ZV_BYTE
-	 && (c = FETCH_CHAR (bytepos),
+	 && (c = FETCH_BYTE (bytepos),
 	     c == ' ' || c == '\t'))
     ++bytepos;

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no