From e412b7e10fd5308ceaf67cdc2b4058a724d178e5 Mon Sep 17 00:00:00 2001 From: Nicky Date: Mon, 18 Feb 2013 23:11:03 +0100 Subject: [PATCH] FIRE-9251; make sure there's no iterator used out of the maps valid range. --- indra/llprimitive/llmodel.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp index 5e119f086b..62cfecab52 100644 --- a/indra/llprimitive/llmodel.cpp +++ b/indra/llprimitive/llmodel.cpp @@ -1735,9 +1735,22 @@ LLModel::weight_list& LLModel::getJointInfluences(const LLVector3& pos) weight_map::iterator iter_up = mSkinWeights.lower_bound(pos); weight_map::iterator iter_down = ++iter_up; + // FIRE-9251; it can happen than iter_up points at end(), in that case iter_down points to end()+1. Adjust iter_up to end()-1 and iter_down to end then. + // This will gurantee we have at least one valid pointer from our map and can use that safely as 'best'. + if( mSkinWeights.end() == iter_up ) + { + iter_down = iter_up; + --iter_up; + } + // + + weight_map::iterator best = iter_up; - F32 min_dist = (iter->first - pos).magVec(); + // FIRE-9251; There is no way iter can be valid here, otherwise we had hit the if branch and not the else branch. + // F32 min_dist = (iter->first - pos).magVec(); + F32 min_dist = (best->first - pos).magVec(); + // bool done = false; while (!done)