From f2a0946a7aebe46470dd5848191e235576e6f906 Mon Sep 17 00:00:00 2001 From: Pascal Massimino Date: Wed, 15 Jun 2016 20:54:52 +0200 Subject: [PATCH] add some asserts to delimit the perimeter of CostManager's operation a small protection in a fairly complex code. Change-Id: I920e10e1fc1c35da2cf486349417048d516ff2b9 --- src/enc/backward_references.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/enc/backward_references.c b/src/enc/backward_references.c index b3d4a80d..c7bddcaf 100644 --- a/src/enc/backward_references.c +++ b/src/enc/backward_references.c @@ -835,6 +835,7 @@ static WEBP_INLINE void UpdateCost(CostManager* const manager, int i, int index, double distance_cost) { int k = i - index; double cost_tmp; + assert(k >= 0 && k < MAX_LENGTH); cost_tmp = distance_cost + manager->cost_cache_[k]; if (manager->costs_[i] > cost_tmp) { @@ -1163,6 +1164,7 @@ static int BackwardReferencesHashChainDistanceOnly( j_max = 1; } else { j_max = (int)ceil(cost_manager->min_cost_cache_ / offset_cost); + assert(j_max >= 1); } // With the values we currently use for the model, offset_cost is