Index: Source/core/svg/SVGAnimationElement.cpp |
diff --git a/Source/core/svg/SVGAnimationElement.cpp b/Source/core/svg/SVGAnimationElement.cpp |
index 2507e8e770254bee41fc3b9940c2cea2480af3e8..e06ef9593a2fcdbed14b108cc4e127a93eaf10bf 100644 |
--- a/Source/core/svg/SVGAnimationElement.cpp |
+++ b/Source/core/svg/SVGAnimationElement.cpp |
@@ -415,10 +415,12 @@ unsigned SVGAnimationElement::calculateKeyTimesIndex(float percent) const |
{ |
unsigned index; |
unsigned keyTimesCount = m_keyTimes.size(); |
- // Compare index + 1 to keyTimesCount because the last keyTimes entry is |
- // required to be 1, and percent can never exceed 1; i.e., the second last |
- // keyTimes entry defines the beginning of the final interval |
- for (index = 1; index + 1 < keyTimesCount; ++index) { |
+ // For linear and spline animations, the last value must be '1'. In those |
+ // cases we don't need to consider the last value, since |percent| is never |
+ // greater than one. |
+ if (keyTimesCount && calcMode() != CalcModeDiscrete) |
+ keyTimesCount--; |
+ for (index = 1; index < keyTimesCount; ++index) { |
if (m_keyTimes[index] > percent) |
break; |
} |
@@ -447,14 +449,15 @@ float SVGAnimationElement::calculatePercentFromKeyPoints(float percent) const |
return m_keyPoints[m_keyPoints.size() - 1]; |
unsigned index = calculateKeyTimesIndex(percent); |
- float fromPercent = m_keyTimes[index]; |
- float toPercent = m_keyTimes[index + 1]; |
float fromKeyPoint = m_keyPoints[index]; |
- float toKeyPoint = m_keyPoints[index + 1]; |
if (calcMode() == CalcModeDiscrete) |
return fromKeyPoint; |
+ ASSERT(index + 1 < m_keyTimes.size()); |
+ float fromPercent = m_keyTimes[index]; |
+ float toPercent = m_keyTimes[index + 1]; |
+ float toKeyPoint = m_keyPoints[index + 1]; |
float keyPointPercent = (percent - fromPercent) / (toPercent - fromPercent); |
if (calcMode() == CalcModeSpline) { |