OSDN Git Service

fix an out-of-bounds memory access
authorMathias Agopian <mathias@google.com>
Fri, 16 Nov 2012 01:19:48 +0000 (17:19 -0800)
committerMathias Agopian <mathias@google.com>
Fri, 16 Nov 2012 01:19:48 +0000 (17:19 -0800)
in this particular case, this OOB is always harmless
(and that's why it didn't get fixed from MR1), however,
it interfers with valgrind debugging.

Change-Id: Ic977e03287e59c4b124a89146c9023bd0cb540a8

libs/gui/BufferQueue.cpp

index 590946a..607e0bd 100644 (file)
@@ -314,10 +314,12 @@ status_t BufferQueue::dequeueBuffer(int *outBuf, sp<Fence>& outFence,
                      * the consumer may still have pending reads of the
                      * buffers in flight.
                      */
-                    bool isOlder = mSlots[i].mFrameNumber <
-                            mSlots[found].mFrameNumber;
-                    if (found < 0 || isOlder) {
-                        found = i;
+                    if (found >= 0) {
+                        bool isOlder = mSlots[i].mFrameNumber <
+                                mSlots[found].mFrameNumber;
+                        if (isOlder) {
+                            found = i;
+                        }
                     }
                 }
             }