From 7306c670eb3ddb471d983a7458eb9f522afd0763 Mon Sep 17 00:00:00 2001 From: Michael Lentine Date: Wed, 30 Jul 2014 13:00:37 -0700 Subject: [PATCH] Add error for format and make sure setActiveConfig fails with an invalid mode. Change-Id: Iacdb5cbad125787f96c64c88d432fc541c4cad1a --- services/surfaceflinger/Android.mk | 2 +- services/surfaceflinger/SurfaceFlinger.cpp | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/services/surfaceflinger/Android.mk b/services/surfaceflinger/Android.mk index f279491f5..183478d65 100644 --- a/services/surfaceflinger/Android.mk +++ b/services/surfaceflinger/Android.mk @@ -83,7 +83,7 @@ else LOCAL_CFLAGS += -DPRESENT_TIME_OFFSET_FROM_VSYNC_NS=0 endif -LOCAL_CFLAGS += -fvisibility=hidden +LOCAL_CFLAGS += -fvisibility=hidden -Werror=format LOCAL_CFLAGS += -std=c++11 LOCAL_SHARED_LIBRARIES := \ diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 6a034ecdc..63ee4e36e 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -637,10 +637,16 @@ status_t SurfaceFlinger::setActiveConfig(const sp& display, int mode) { int mode) : mFlinger(flinger), mDisplay(disp) { mMode = mode; } virtual bool handler() { + Vector configs; + mFlinger.getDisplayConfigs(mDisplay, &configs); + if(mMode < 0 || mMode >= configs.size()) { + ALOGE("Attempt to set active config = %d for display with %d configs", + mMode, configs.size()); + } sp hw(mFlinger.getDisplayDevice(mDisplay)); if (hw == NULL) { ALOGE("Attempt to set active config = %d for null display %p", - mDisplay.get(), mMode); + mMode, mDisplay.get()); } else if (hw->getDisplayType() >= DisplayDevice::DISPLAY_VIRTUAL) { ALOGW("Attempt to set active config = %d for virtual display", mMode); @@ -2267,7 +2273,7 @@ void SurfaceFlinger::setPowerMode(const sp& display, int mode) { sp hw(mFlinger.getDisplayDevice(mDisplay)); if (hw == NULL) { ALOGE("Attempt to set power mode = %d for null display %p", - mDisplay.get(), mMode); + mMode, mDisplay.get()); } else if (hw->getDisplayType() >= DisplayDevice::DISPLAY_VIRTUAL) { ALOGW("Attempt to set power mode = %d for virtual display", mMode);