From 78e45e900f28c8607e02d8b22ee199f32e69c6e1 Mon Sep 17 00:00:00 2001 From: riidefi <34194588+riidefi@users.noreply.github.com> Date: Sat, 24 Aug 2024 00:38:55 -0700 Subject: [PATCH] [szs] MK8: Remove sneaky reliance on unsigned underflow for range check (from implicit conversion) --- source/szs/src/MK8.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/szs/src/MK8.hpp b/source/szs/src/MK8.hpp index 78c7175c..905b3265 100644 --- a/source/szs/src/MK8.hpp +++ b/source/szs/src/MK8.hpp @@ -107,7 +107,7 @@ static inline bool search(Match& match, const s32 search_pos_immut, // There are no deletions from the hash chains; the algorithm // simply discards matches that are too old. - if (data_pos - search_pos > SEARCH_WINDOW_SIZE) { + if (search_pos > data_pos || data_pos > search_pos + SEARCH_WINDOW_SIZE) { return false; } @@ -161,6 +161,8 @@ static inline bool search(Match& match, const s32 search_pos_immut, } search_pos = work.search_pos(search_pos); + // There are no deletions from the hash chains; the algorithm + // simply discards matches that are too old. if (search_pos <= search_pos_min) { break; }