From f17b95e99228829d78e6c296929969fdb71f5a13 Mon Sep 17 00:00:00 2001 From: James Zern Date: Wed, 24 Sep 2014 23:51:46 -0700 Subject: [PATCH] AssignSegments: quiet -Warray-bounds warning the number of segments are previously validated, but an explicit check is needed to avoid a warning under gcc-4.9 (cherry picked from commit c8a87bb62d64b03087499e9277937fe76f1f1726) Change-Id: Ifa7c0dd7f3f075b3860fa8ec176d2c98ff54fcea --- src/enc/analysis.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/enc/analysis.c b/src/enc/analysis.c index 934d0912..e019465b 100644 --- a/src/enc/analysis.c +++ b/src/enc/analysis.c @@ -141,7 +141,11 @@ static void MergeHistograms(const VP8Histogram* const in, static void AssignSegments(VP8Encoder* const enc, const int alphas[MAX_ALPHA + 1]) { - const int nb = enc->segment_hdr_.num_segments_; + // 'num_segments_' is previously validated and <= NUM_MB_SEGMENTS, but an + // explicit check is needed to avoid spurious warning about 'n + 1' exceeding + // array bounds of 'centers' with some compilers (noticed with gcc-4.9). + const int nb = (enc->segment_hdr_.num_segments_ < NUM_MB_SEGMENTS) ? + enc->segment_hdr_.num_segments_ : NUM_MB_SEGMENTS; int centers[NUM_MB_SEGMENTS]; int weighted_average = 0; int map[MAX_ALPHA + 1];