From 20071b66afd467bc87acea2e2c42cff90757f743 Mon Sep 17 00:00:00 2001
From: James Turner <zakalawe@mac.com>
Date: Tue, 26 Jun 2012 15:16:03 +0100
Subject: [PATCH] Fix an edge case in flight-plan inserts.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When inserting with an invalid index, ensure we return the leg based on the fixed-up index, not the original one. Thanks to Matthias Götz for the catch!
---
 src/Navaids/FlightPlan.cxx | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Navaids/FlightPlan.cxx b/src/Navaids/FlightPlan.cxx
index 5f5ba5e71..b5ff28b45 100644
--- a/src/Navaids/FlightPlan.cxx
+++ b/src/Navaids/FlightPlan.cxx
@@ -148,7 +148,7 @@ FlightPlan::Leg* FlightPlan::insertWayptAtIndex(Waypt* aWpt, int aIndex)
   }
   
   insertWayptsAtIndex(wps, index);
-  return legAtIndex(aIndex);
+  return legAtIndex(index);
 }
   
 void FlightPlan::insertWayptsAtIndex(const WayptVec& wps, int aIndex)