From 18a37393c520819659922b7fb0a5e3f54c79c949 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Sun, 20 Jan 2013 14:30:53 -0200 Subject: [PATCH] Limit path finding max complexity --- src/client/map.cpp | 7 +++++++ src/framework/ui/uitextedit.cpp | 6 +----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/client/map.cpp b/src/client/map.cpp index d06b7610..a6d25d17 100644 --- a/src/client/map.cpp +++ b/src/client/map.cpp @@ -540,6 +540,8 @@ std::tuple, Otc::PathFindResult> Map::findPath(const } }; + const uint MAX_COMPLEXITY = 100000; + std::tuple, Otc::PathFindResult> ret; std::vector& dirs = std::get<0>(ret); Otc::PathFindResult& result = std::get<1>(ret); @@ -575,6 +577,11 @@ std::tuple, Otc::PathFindResult> Map::findPath(const break; } + if(nodes.size() > MAX_COMPLEXITY) { + result = Otc::PathFindResultTooFar; + break; + } + // path found if(currentNode->pos == goalPos && (!foundNode || currentNode->cost < foundNode->cost)) foundNode = currentNode; diff --git a/src/framework/ui/uitextedit.cpp b/src/framework/ui/uitextedit.cpp index e4557adf..e6e6ca51 100644 --- a/src/framework/ui/uitextedit.cpp +++ b/src/framework/ui/uitextedit.cpp @@ -714,7 +714,7 @@ bool UITextEdit::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeat if(UIWidgetPtr parent = getParent()) parent->focusPreviousChild(Fw::KeyboardFocusReason); return true; - } else if(keyCode == Fw::KeyRight || keyCode == Fw::KeyLeft || keyCode == Fw::KeyUp || keyCode == Fw::KeyDown) { + } else if(keyCode == Fw::KeyRight || keyCode == Fw::KeyLeft) { int oldCursorPos = m_cursorPos; @@ -722,10 +722,6 @@ bool UITextEdit::onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeat moveCursorHorizontally(true); else if(keyCode == Fw::KeyLeft) // move cursor left moveCursorHorizontally(false); - else if(keyCode == Fw::KeyUp) // move cursor right - moveCursorVertically(true); - else if(keyCode == Fw::KeyDown) // move cursor left - moveCursorVertically(false); if(m_shiftNavigation) clearSelection();