From d347e37be470c1c63841dbe036de5c29c0401c38 Mon Sep 17 00:00:00 2001 From: Derek Foreman Date: Thu, 10 Nov 2022 07:34:14 -0600 Subject: [PATCH] libweston: change div by 0 behaviour in coordinate conversion Let's simplify this code by asserting, and letting it explode naturally (return Inf, possibly SIGFPE depending on external factors) if compiled NDEBUG, instead of a contained explosion (safely returning 0). If this actually happens it's Really Bad, so we'd like to catch is ASAP, especially in CI. Signed-off-by: Derek Foreman --- libweston/compositor.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/libweston/compositor.c b/libweston/compositor.c index 231c9071..4dad3981 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -655,14 +655,7 @@ weston_view_to_global_float(struct weston_view *view, weston_matrix_transform(&view->transform.matrix, &v); - if (fabsf(v.f[3]) < 1e-6) { - weston_log("warning: numerical instability in " - "%s(), divisor = %g\n", __func__, - v.f[3]); - *x = 0; - *y = 0; - return; - } + assert(fabs(v.f[3]) > 1e-6); *x = v.f[0] / v.f[3]; *y = v.f[1] / v.f[3]; @@ -1468,14 +1461,7 @@ weston_view_from_global_float(struct weston_view *view, weston_matrix_transform(&view->transform.inverse, &v); - if (fabsf(v.f[3]) < 1e-6) { - weston_log("warning: numerical instability in " - "weston_view_from_global(), divisor = %g\n", - v.f[3]); - *vx = 0; - *vy = 0; - return; - } + assert(fabs(v.f[3]) > 1e-6); *vx = v.f[0] / v.f[3]; *vy = v.f[1] / v.f[3];