emacs-diffs
[Top][All Lists]
Advanced

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

scratch/tty-child-frames dac51f1f66e: Fix UB in line_hash_code


From: Gerd Moellmann
Subject: scratch/tty-child-frames dac51f1f66e: Fix UB in line_hash_code
Date: Tue, 22 Oct 2024 23:17:10 -0400 (EDT)

branch: scratch/tty-child-frames
commit dac51f1f66ef93cec6d9ea17e74a193de9ae1ff3
Author: Paul Eggert <eggert@cs.ucla.edu>
Commit: Gerd Möllmann <gerd@gnu.org>

    Fix UB in line_hash_code
    
    * src/dispnew.c (line_hash_code): Avoid undefined behavior on
    integer overflow.
---
 src/dispnew.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/dispnew.c b/src/dispnew.c
index 200ffaaca21..1ece9cc1d45 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -1175,12 +1175,12 @@ line_hash_code (struct frame *f, struct glyph_row *row)
       while (glyph < end)
        {
          int c = glyph->u.ch;
-         int face_id = glyph->face_id;
+         unsigned int face_id = glyph->face_id;
          /* Struct frame can move with igc, and so on.  But we need
             something that takes different frames into account.  Use the
             face_cache pointer for that which is malloc'd.  */
          if (glyph->frame && glyph->frame != f)
-           face_id += (ptrdiff_t) glyph->frame->face_cache;
+           face_id += (uintptr_t) glyph->frame->face_cache;
          if (FRAME_MUST_WRITE_SPACES (f))
            c -= SPACEGLYPH;
          hash = (((hash << 4) + (hash >> 24)) & 0x0fffffff) + c;



reply via email to

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