From ed78cda6adadf28423cc859677fdab36a1947e97 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Thu, 4 Jun 2020 09:35:52 +0200 Subject: [PATCH] sources: check for negative distance This is not expected to happen, but make sure the endpoints of each source are in the right order (i.e. the distance is not negative) to prevent getting a negative depth in the selection. --- sources.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sources.c b/sources.c index e625c68..f134c78 100644 --- a/sources.c +++ b/sources.c @@ -828,8 +828,9 @@ SRC_SelectSource(SRC_Instance updated_inst) si->hi_limit += extra_disp; } - /* Require the root distance to be below the allowed maximum */ - if (si->root_distance > max_distance) { + /* Require the root distance to be below the allowed maximum and the + endpoints to be in the right order (i.e. a non-negative distance) */ + if (!(si->root_distance <= max_distance && si->lo_limit <= si->hi_limit)) { mark_source(sources[i], SRC_BAD_DISTANCE); continue; }