From c7995a8a49315d0e7378606c9208caa0400afdd2 Mon Sep 17 00:00:00 2001
From: Kyle Repinski <repinski23@gmail.com>
Date: Sun, 19 Apr 2015 01:03:46 -0500
Subject: [PATCH] Fix compiler issues uncovered at higher optimization levels.

amrwbenc: Fix incorrect array-bounds warning/error.
m4v_h263: dec: Fix bogus strict-overflow warning/error.
af: Fix ICE in AudioMixer::track__NoResample.

Change-Id: I2b44072eff6499026034a82107d9dfc6195a6810
---
 media/libstagefright/codecs/amrwbenc/src/isp_az.c           | 13 ++++++-------
 .../codecs/m4v_h263/dec/src/deringing_luma.cpp              |  4 ++--
 services/audioflinger/AudioMixer.cpp                        |  2 +-
 3 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/media/libstagefright/codecs/amrwbenc/src/isp_az.c b/media/libstagefright/codecs/amrwbenc/src/isp_az.c
index 62e29e7..6423ec8 100644
--- a/media/libstagefright/codecs/amrwbenc/src/isp_az.c
+++ b/media/libstagefright/codecs/amrwbenc/src/isp_az.c
@@ -42,7 +42,7 @@ void Isp_Az(
                                               /*     1   : adaptive scaling enabled  */
        )
 {
-    Word32 i, j;
+    Word16 i, j;
     Word16 hi, lo;
     Word32 f1[NC16k + 1], f2[NC16k];
     Word16 nc;
@@ -58,18 +58,17 @@ void Isp_Az(
         {
             f1[i] = f1[i] << 2;
         }
-    } else
-        Get_isp_pol(&isp[0], f1, nc);
-
-    if (nc > 8)
-    {
         Get_isp_pol_16kHz(&isp[1], f2, (nc - 1));
         for (i = 0; i <= nc - 1; i++)
         {
             f2[i] = f2[i] << 2;
         }
-    } else
+	}
+	else
+	{
+	Get_isp_pol(&isp[0], f1, nc);
         Get_isp_pol(&isp[1], f2, (nc - 1));
+	}
 
     /*-----------------------------------------------------*
      *  Multiply F2(z) by (1 - z^-2)                       *
diff --git a/media/libstagefright/codecs/m4v_h263/dec/src/deringing_luma.cpp b/media/libstagefright/codecs/m4v_h263/dec/src/deringing_luma.cpp
index b5574b4..1319251 100644
--- a/media/libstagefright/codecs/m4v_h263/dec/src/deringing_luma.cpp
+++ b/media/libstagefright/codecs/m4v_h263/dec/src/deringing_luma.cpp
@@ -78,7 +78,7 @@ void Deringing_Luma(
         for (v_blk = 0; v_blk < MBSIZE; v_blk += BLKSIZE)
         {
             v0 = ((v_blk - 1) >= 1) ? (v_blk - 1) : 1;
-            for (h_blk = MB_H; h_blk < MB_H + MBSIZE; h_blk += BLKSIZE)
+            for (h_blk = MB_H; (unsigned int)h_blk < (unsigned int)((unsigned int)MB_H + (unsigned int)MBSIZE); h_blk += BLKSIZE)
             {
                 h0 = ((h_blk - 1) >= 1) ? (h_blk - 1) : 1;
 
@@ -129,7 +129,7 @@ void Deringing_Luma(
         }
 
         blks = 0;
-        for (v_blk = MB_V; v_blk < MB_V + MBSIZE; v_blk += BLKSIZE)
+        for (v_blk = MB_V; (unsigned int)v_blk < (unsigned int)((unsigned int)MB_V + (unsigned int)MBSIZE); v_blk += BLKSIZE)
         {
             v0 = v_blk - 1;
             for (h_blk = 0; h_blk < MBSIZE; h_blk += BLKSIZE)
diff --git a/services/audioflinger/AudioMixer.cpp b/services/audioflinger/AudioMixer.cpp
index 806eaf1..a12d595 100644
--- a/services/audioflinger/AudioMixer.cpp
+++ b/services/audioflinger/AudioMixer.cpp
@@ -1934,7 +1934,7 @@ void AudioMixer::track__Resample(track_t* t, TO* out, size_t outFrameCount, TO*
  * TA: int32_t (Q4.27)
  */
 template <int MIXTYPE, typename TO, typename TI, typename TA>
-void AudioMixer::track__NoResample(track_t* t, TO* out, size_t frameCount,
+void __attribute__((optimize("no-tree-vectorize"))) AudioMixer::track__NoResample(track_t* t, TO* out, size_t frameCount,
         TO* temp __unused, TA* aux)
 {
     ALOGVV("track__NoResample\n");
-- 
2.7.1

