emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-27 df91c94: Fix access to single-byte characters in buffer text


From: Eli Zaretskii
Subject: emacs-27 df91c94: Fix access to single-byte characters in buffer text
Date: Mon, 25 May 2020 10:08:28 -0400 (EDT)

branch: emacs-27
commit df91c94ca8e87a106c1e8e573802d4e299d26404
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Fix access to single-byte characters in buffer text
    
    * src/xdisp.c (get_visually_first_element)
    (Fbidi_find_overridden_directionality):
    * src/cmds.c (Fend_of_line): Use FETCH_BYTE instead of FETCH_CHAR,
    and byte position instead of character position, to access
    individual bytes of buffer text.  This avoids producing invalid
    characters and accessing wrong buffer positions.  (Bug#41520)
---
 src/cmds.c  | 4 ++--
 src/xdisp.c | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/cmds.c b/src/cmds.c
index 5d7a45e..9914b7a 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -203,7 +203,7 @@ to t.  */)
       SET_PT (newpos);
 
       if (PT > newpos
-         && FETCH_CHAR (PT - 1) == '\n')
+         && FETCH_BYTE (PT_BYTE - 1) == '\n')
        {
          /* If we skipped over a newline that follows
             an invisible intangible run,
@@ -214,7 +214,7 @@ to t.  */)
          break;
        }
       else if (PT > newpos && PT < ZV
-              && FETCH_CHAR (PT) != '\n')
+              && FETCH_BYTE (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 1e86589..bff6218 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -8264,8 +8264,8 @@ 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_CHAR (it->bidi_it.bytepos) == '\n')))
+              && (FETCH_BYTE (it->bidi_it.bytepos - 1) == '\n'
+                  || FETCH_BYTE (it->bidi_it.bytepos) == '\n')))
     {
       /* If we are at the beginning of a line/string, we can produce
         the next element right away.  */
@@ -24157,7 +24157,7 @@ the `bidi-class' property of a character.  */)
          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;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]