aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2024-02-11 10:00:33 +0800
committerPo Lu2024-02-11 10:01:31 +0800
commite67e7185ce81e59c90741f92c2ba3209412f417e (patch)
treeed4a3db6efaeb3fca98df1e0e36be8b048054741 /src
parent7a0ee5d65f214102734dd22edb641b164a1b73af (diff)
downloademacs-e67e7185ce81e59c90741f92c2ba3209412f417e.tar.gz
emacs-e67e7185ce81e59c90741f92c2ba3209412f417e.zip
Fix signed/unsigned promotion errors involving Emacs_Rectangle
* src/androidterm.c (android_note_mouse_movement): * src/pgtkterm.c (note_mouse_movement): * src/xdisp.c (get_glyph_string_clip_rects, remember_mouse_glyph) (expose_area, expose_window, gui_intersect_rectangles): Cast width or height fields in Emacs_Rectangles to int before summing with or subtracting them from their coordinate fields, as they are unsigned outside X, and the sign of the coordinates is thus not preserved.
Diffstat (limited to 'src')
-rw-r--r--src/androidterm.c4
-rw-r--r--src/pgtkterm.c4
-rw-r--r--src/xdisp.c33
3 files changed, 21 insertions, 20 deletions
diff --git a/src/androidterm.c b/src/androidterm.c
index d4612bb20fa..2bd2b45743d 100644
--- a/src/androidterm.c
+++ b/src/androidterm.c
@@ -495,8 +495,8 @@ android_note_mouse_movement (struct frame *frame,
495 /* Has the mouse moved off the glyph it was on at the last sighting? */ 495 /* Has the mouse moved off the glyph it was on at the last sighting? */
496 r = &dpyinfo->last_mouse_glyph; 496 r = &dpyinfo->last_mouse_glyph;
497 if (frame != dpyinfo->last_mouse_glyph_frame 497 if (frame != dpyinfo->last_mouse_glyph_frame
498 || event->x < r->x || event->x >= r->x + r->width 498 || event->x < r->x || event->x >= r->x + (int) r->width
499 || event->y < r->y || event->y >= r->y + r->height) 499 || event->y < r->y || event->y >= r->y + (int) r->height)
500 { 500 {
501 frame->mouse_moved = true; 501 frame->mouse_moved = true;
502 note_mouse_highlight (frame, event->x, event->y); 502 note_mouse_highlight (frame, event->x, event->y);
diff --git a/src/pgtkterm.c b/src/pgtkterm.c
index b731f52983d..1ec6bfcda4e 100644
--- a/src/pgtkterm.c
+++ b/src/pgtkterm.c
@@ -5825,8 +5825,8 @@ note_mouse_movement (struct frame *frame,
5825 /* Has the mouse moved off the glyph it was on at the last sighting? */ 5825 /* Has the mouse moved off the glyph it was on at the last sighting? */
5826 r = &dpyinfo->last_mouse_glyph; 5826 r = &dpyinfo->last_mouse_glyph;
5827 if (frame != dpyinfo->last_mouse_glyph_frame 5827 if (frame != dpyinfo->last_mouse_glyph_frame
5828 || event->x < r->x || event->x >= r->x + r->width 5828 || event->x < r->x || event->x >= r->x + (int) r->width
5829 || event->y < r->y || event->y >= r->y + r->height) 5829 || event->y < r->y || event->y >= r->y + (int) r->height)
5830 { 5830 {
5831 frame->mouse_moved = true; 5831 frame->mouse_moved = true;
5832 dpyinfo->last_mouse_scroll_bar = NULL; 5832 dpyinfo->last_mouse_scroll_bar = NULL;
diff --git a/src/xdisp.c b/src/xdisp.c
index 2dcf0d58a14..0b8347214c7 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -2508,7 +2508,7 @@ get_glyph_string_clip_rects (struct glyph_string *s, NativeRectangle *rects, int
2508 r.x = s->clip_head->x; 2508 r.x = s->clip_head->x;
2509 } 2509 }
2510 if (s->clip_tail) 2510 if (s->clip_tail)
2511 if (r.x + r.width > s->clip_tail->x + s->clip_tail->background_width) 2511 if (r.x + (int) r.width > s->clip_tail->x + s->clip_tail->background_width)
2512 { 2512 {
2513 if (s->clip_tail->x + s->clip_tail->background_width >= r.x) 2513 if (s->clip_tail->x + s->clip_tail->background_width >= r.x)
2514 r.width = s->clip_tail->x + s->clip_tail->background_width - r.x; 2514 r.width = s->clip_tail->x + s->clip_tail->background_width - r.x;
@@ -2588,7 +2588,7 @@ get_glyph_string_clip_rects (struct glyph_string *s, NativeRectangle *rects, int
2588 height = max (FRAME_LINE_HEIGHT (s->f), glyph->ascent + glyph->descent); 2588 height = max (FRAME_LINE_HEIGHT (s->f), glyph->ascent + glyph->descent);
2589 if (height < r.height) 2589 if (height < r.height)
2590 { 2590 {
2591 max_y = r.y + r.height; 2591 max_y = r.y + (int) r.height;
2592 r.y = min (max_y, max (r.y, s->ybase + glyph->descent - height)); 2592 r.y = min (max_y, max (r.y, s->ybase + glyph->descent - height));
2593 r.height = min (max_y - r.y, height); 2593 r.height = min (max_y - r.y, height);
2594 } 2594 }
@@ -2629,7 +2629,7 @@ get_glyph_string_clip_rects (struct glyph_string *s, NativeRectangle *rects, int
2629 if (s->for_overlaps & OVERLAPS_PRED) 2629 if (s->for_overlaps & OVERLAPS_PRED)
2630 { 2630 {
2631 rs[i] = r; 2631 rs[i] = r;
2632 if (r.y + r.height > row_y) 2632 if (r.y + (int) r.height > row_y)
2633 { 2633 {
2634 if (r.y < row_y) 2634 if (r.y < row_y)
2635 rs[i].height = row_y - r.y; 2635 rs[i].height = row_y - r.y;
@@ -2643,10 +2643,10 @@ get_glyph_string_clip_rects (struct glyph_string *s, NativeRectangle *rects, int
2643 rs[i] = r; 2643 rs[i] = r;
2644 if (r.y < row_y + s->row->visible_height) 2644 if (r.y < row_y + s->row->visible_height)
2645 { 2645 {
2646 if (r.y + r.height > row_y + s->row->visible_height) 2646 if (r.y + (int) r.height > row_y + s->row->visible_height)
2647 { 2647 {
2648 rs[i].y = row_y + s->row->visible_height; 2648 rs[i].y = row_y + s->row->visible_height;
2649 rs[i].height = r.y + r.height - rs[i].y; 2649 rs[i].height = r.y + (int) r.height - rs[i].y;
2650 } 2650 }
2651 else 2651 else
2652 rs[i].height = 0; 2652 rs[i].height = 0;
@@ -2831,7 +2831,7 @@ remember_mouse_glyph (struct frame *f, int gx, int gy, NativeRectangle *rect)
2831 text_glyph: 2831 text_glyph:
2832 gr = 0; gy = 0; 2832 gr = 0; gy = 0;
2833 for (; r <= end_row && r->enabled_p; ++r) 2833 for (; r <= end_row && r->enabled_p; ++r)
2834 if (r->y + r->height > y) 2834 if (r->y + (int) r->height > y)
2835 { 2835 {
2836 gr = r; gy = r->y; 2836 gr = r; gy = r->y;
2837 break; 2837 break;
@@ -2931,7 +2931,7 @@ remember_mouse_glyph (struct frame *f, int gx, int gy, NativeRectangle *rect)
2931 row_glyph: 2931 row_glyph:
2932 gr = 0, gy = 0; 2932 gr = 0, gy = 0;
2933 for (; r <= end_row && r->enabled_p; ++r) 2933 for (; r <= end_row && r->enabled_p; ++r)
2934 if (r->y + r->height > y) 2934 if (r->y + (int) r->height > y)
2935 { 2935 {
2936 gr = r; gy = r->y; 2936 gr = r; gy = r->y;
2937 break; 2937 break;
@@ -36464,7 +36464,7 @@ expose_area (struct window *w, struct glyph_row *row, const Emacs_Rectangle *r,
36464 /* Use a signed int intermediate value to avoid catastrophic 36464 /* Use a signed int intermediate value to avoid catastrophic
36465 failures due to comparison between signed and unsigned, when 36465 failures due to comparison between signed and unsigned, when
36466 x is negative (can happen for wide images that are hscrolled). */ 36466 x is negative (can happen for wide images that are hscrolled). */
36467 int r_end = r->x + r->width; 36467 int r_end = r->x + (int) r->width;
36468 while (last < end && x < r_end) 36468 while (last < end && x < r_end)
36469 { 36469 {
36470 x += last->pixel_width; 36470 x += last->pixel_width;
@@ -36763,7 +36763,7 @@ expose_window (struct window *w, const Emacs_Rectangle *fr)
36763 /* Use a signed int intermediate value to avoid catastrophic 36763 /* Use a signed int intermediate value to avoid catastrophic
36764 failures due to comparison between signed and unsigned, when 36764 failures due to comparison between signed and unsigned, when
36765 y0 or y1 is negative (can happen for tall images). */ 36765 y0 or y1 is negative (can happen for tall images). */
36766 int r_bottom = r.y + r.height; 36766 int r_bottom = r.y + (int) r.height;
36767 36767
36768 /* We must temporarily switch to the window's buffer, in case 36768 /* We must temporarily switch to the window's buffer, in case
36769 the fringe face has been remapped in that buffer's 36769 the fringe face has been remapped in that buffer's
@@ -36810,7 +36810,7 @@ expose_window (struct window *w, const Emacs_Rectangle *fr)
36810 /* We must redraw a row overlapping the exposed area. */ 36810 /* We must redraw a row overlapping the exposed area. */
36811 if (y0 < r.y 36811 if (y0 < r.y
36812 ? y0 + row->phys_height > r.y 36812 ? y0 + row->phys_height > r.y
36813 : y0 + row->ascent - row->phys_ascent < r.y +r.height) 36813 : y0 + row->ascent - row->phys_ascent < r.y + (int) r.height)
36814 { 36814 {
36815 if (first_overlapping_row == NULL) 36815 if (first_overlapping_row == NULL)
36816 first_overlapping_row = row; 36816 first_overlapping_row = row;
@@ -36989,7 +36989,7 @@ gui_intersect_rectangles (const Emacs_Rectangle *r1, const Emacs_Rectangle *r2,
36989 const Emacs_Rectangle *upper, *lower; 36989 const Emacs_Rectangle *upper, *lower;
36990 bool intersection_p = false; 36990 bool intersection_p = false;
36991 36991
36992 /* Rearrange so that R1 is the left-most rectangle. */ 36992 /* Rearrange so that left is the left-most rectangle. */
36993 if (r1->x < r2->x) 36993 if (r1->x < r2->x)
36994 left = r1, right = r2; 36994 left = r1, right = r2;
36995 else 36995 else
@@ -36997,13 +36997,14 @@ gui_intersect_rectangles (const Emacs_Rectangle *r1, const Emacs_Rectangle *r2,
36997 36997
36998 /* X0 of the intersection is right.x0, if this is inside R1, 36998 /* X0 of the intersection is right.x0, if this is inside R1,
36999 otherwise there is no intersection. */ 36999 otherwise there is no intersection. */
37000 if (right->x <= left->x + left->width) 37000 if (right->x <= left->x + (int) left->width)
37001 { 37001 {
37002 result->x = right->x; 37002 result->x = right->x;
37003 37003
37004 /* The right end of the intersection is the minimum of 37004 /* The right end of the intersection is the minimum of
37005 the right ends of left and right. */ 37005 the right ends of left and right. */
37006 result->width = (min (left->x + left->width, right->x + right->width) 37006 result->width = (min (left->x + (int) left->width,
37007 right->x + (int) right->width)
37007 - result->x); 37008 - result->x);
37008 37009
37009 /* Same game for Y. */ 37010 /* Same game for Y. */
@@ -37014,14 +37015,14 @@ gui_intersect_rectangles (const Emacs_Rectangle *r1, const Emacs_Rectangle *r2,
37014 37015
37015 /* The upper end of the intersection is lower.y0, if this is inside 37016 /* The upper end of the intersection is lower.y0, if this is inside
37016 of upper. Otherwise, there is no intersection. */ 37017 of upper. Otherwise, there is no intersection. */
37017 if (lower->y <= upper->y + upper->height) 37018 if (lower->y <= upper->y + (int) upper->height)
37018 { 37019 {
37019 result->y = lower->y; 37020 result->y = lower->y;
37020 37021
37021 /* The lower end of the intersection is the minimum of the lower 37022 /* The lower end of the intersection is the minimum of the lower
37022 ends of upper and lower. */ 37023 ends of upper and lower. */
37023 result->height = (min (lower->y + lower->height, 37024 result->height = (min (lower->y + (int) lower->height,
37024 upper->y + upper->height) 37025 upper->y + (int) upper->height)
37025 - result->y); 37026 - result->y);
37026 intersection_p = true; 37027 intersection_p = true;
37027 } 37028 }