From c7213092415732272aa5ccd4547940bf9fe4c7b5 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 10 Nov 2020 20:51:43 +0100 Subject: Fix asan errors on X11 Fun with union punning. The different sizes mean that stuff on the stack could be copied to the destination event. I don't think this would cause a concrete issue (the contents of the event past the expose are irrelevant) but asan quite reasonably has a problem with it. --- src/x11.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'src/x11.c') diff --git a/src/x11.c b/src/x11.c index b462dd0..93ed599 100644 --- a/src/x11.c +++ b/src/x11.c @@ -875,20 +875,18 @@ puglWaitForEvent(PuglView* view) #endif static void -mergeExposeEvents(PuglEvent* dst, const PuglEvent* src) +mergeExposeEvents(PuglEventExpose* dst, const PuglEventExpose* src) { if (!dst->type) { *dst = *src; } else { - const double max_x = MAX(dst->expose.x + dst->expose.width, - src->expose.x + src->expose.width); - const double max_y = MAX(dst->expose.y + dst->expose.height, - src->expose.y + src->expose.height); - - dst->expose.x = MIN(dst->expose.x, src->expose.x); - dst->expose.y = MIN(dst->expose.y, src->expose.y); - dst->expose.width = max_x - dst->expose.x; - dst->expose.height = max_y - dst->expose.y; + const double max_x = MAX(dst->x + dst->width, src->x + src->width); + const double max_y = MAX(dst->y + dst->height, src->y + src->height); + + dst->x = MIN(dst->x, src->x); + dst->y = MIN(dst->y, src->y); + dst->width = max_x - dst->x; + dst->height = max_y - dst->y; } } @@ -1063,7 +1061,7 @@ puglDispatchX11Events(PuglWorld* world) if (event.type == PUGL_EXPOSE) { // Expand expose event to be dispatched after loop - mergeExposeEvents(&view->impl->pendingExpose, &event); + mergeExposeEvents(&view->impl->pendingExpose.expose, &event.expose); } else if (event.type == PUGL_CONFIGURE) { // Expand configure event to be dispatched after loop view->impl->pendingConfigure = event; @@ -1153,7 +1151,7 @@ puglPostRedisplayRect(PuglView* view, PuglRect rect) if (view->world->impl->dispatchingEvents) { // Currently dispatching events, add/expand expose for the loop end - mergeExposeEvents(&view->impl->pendingExpose, (const PuglEvent*)&event); + mergeExposeEvents(&view->impl->pendingExpose.expose, &event); } else if (view->visible) { // Not dispatching events, send an X expose so we wake up next time return puglSendEvent(view, (const PuglEvent*)&event); -- cgit v1.2.1