From 1fca85784c2cde87f408e2f12700d1dc8b35b860 Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Tue, 14 Jan 2014 21:00:44 +0100 Subject: [PATCH] OP-1122 OP-1145 added more path plan checks : - empty plan (i.e. no waypoints defined) - out of range waypoint and path action ids +review OPReview-609 --- flight/modules/PathPlanner/pathplanner.c | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/flight/modules/PathPlanner/pathplanner.c b/flight/modules/PathPlanner/pathplanner.c index 3e705d99e..93e664b85 100644 --- a/flight/modules/PathPlanner/pathplanner.c +++ b/flight/modules/PathPlanner/pathplanner.c @@ -265,10 +265,16 @@ static uint8_t checkPathPlan() uint16_t actionCount; uint8_t pathCrc; PathPlanData pathPlan; + //WaypointData waypoint; // using global instead (?) + //PathActionData action; // using global instead (?) PathPlanGet(&pathPlan); waypointCount = pathPlan.WaypointCount; + if (waypointCount == 0) { + // an empty path plan is invalid + return false; + } actionCount = pathPlan.PathActionCount; // check count consistency @@ -295,6 +301,28 @@ static uint8_t checkPathPlan() return false; } + // waypoint consistency + for (i = 0; i < waypointCount; i++) { + WaypointInstGet(i, &waypoint); + if (waypoint.Action >= actionCount) { + // path action id is out of range + return false; + } + } + + // path action consistency + for (i = 0; i < actionCount; i++) { + PathActionInstGet(i, &pathAction); + if (pathAction.ErrorDestination >= waypointCount) { + // waypoint id is out of range + return false; + } + if (pathAction.JumpDestination >= waypointCount) { + // waypoint id is out of range + return false; + } + } + // path plan passed checks return true;