From 57afd0ab37060795b8ae5a6b868a918a2ee75810 Mon Sep 17 00:00:00 2001 From: Tobias Frost Date: Sat, 2 Mar 2019 23:43:08 +0100 Subject: [PATCH] Fix range check bug in FileList::seek() (#13286) When `count()` returns 0, `pos > (count()-1)` will always yield `true` due to integer underflow. --- Marlin/src/lcd/extensible_ui/ui_api.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/lcd/extensible_ui/ui_api.cpp b/Marlin/src/lcd/extensible_ui/ui_api.cpp index 88b5d35a4..7165b5eef 100644 --- a/Marlin/src/lcd/extensible_ui/ui_api.cpp +++ b/Marlin/src/lcd/extensible_ui/ui_api.cpp @@ -688,7 +688,7 @@ namespace ExtUI { bool FileList::seek(const uint16_t pos, const bool skip_range_check) { #if ENABLED(SDSUPPORT) - if (!skip_range_check && pos > (count() - 1)) return false; + if (!skip_range_check && (pos + 1) > count()) return false; const uint16_t nr = #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA) count() - 1 -