add some asserts to delimit the perimeter of CostManager's operation
a small protection in a fairly complex code. Change-Id: I920e10e1fc1c35da2cf486349417048d516ff2b9
This commit is contained in:
		@@ -835,6 +835,7 @@ static WEBP_INLINE void UpdateCost(CostManager* const manager, int i, int index,
 | 
				
			|||||||
                                   double distance_cost) {
 | 
					                                   double distance_cost) {
 | 
				
			||||||
  int k = i - index;
 | 
					  int k = i - index;
 | 
				
			||||||
  double cost_tmp;
 | 
					  double cost_tmp;
 | 
				
			||||||
 | 
					  assert(k >= 0 && k < MAX_LENGTH);
 | 
				
			||||||
  cost_tmp = distance_cost + manager->cost_cache_[k];
 | 
					  cost_tmp = distance_cost + manager->cost_cache_[k];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (manager->costs_[i] > cost_tmp) {
 | 
					  if (manager->costs_[i] > cost_tmp) {
 | 
				
			||||||
@@ -1163,6 +1164,7 @@ static int BackwardReferencesHashChainDistanceOnly(
 | 
				
			|||||||
        j_max = 1;
 | 
					        j_max = 1;
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        j_max = (int)ceil(cost_manager->min_cost_cache_ / offset_cost);
 | 
					        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
 | 
					      // With the values we currently use for the model, offset_cost is
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user