sdm: fix stack corruption

Cache application layers only when the application layer count is
less than 32.

Change-Id: Ica08a49e903985313bb7b9db143d0be3fda1337c
diff --git a/sdm/libs/core/core_impl.cpp b/sdm/libs/core/core_impl.cpp
index f017d8d..d9c8500 100644
--- a/sdm/libs/core/core_impl.cpp
+++ b/sdm/libs/core/core_impl.cpp
@@ -65,7 +65,7 @@
     }
 
     error = create_extension_intf_(EXTENSION_VERSION_TAG, &extension_intf_);
-    if(error != kErrorNone) {
+    if (error != kErrorNone) {
       DLOGE("Unable to create interface");
       ::dlclose(extension_lib_);
       return error;
diff --git a/sdm/libs/core/strategy.cpp b/sdm/libs/core/strategy.cpp
index 16e3f63..183384e 100644
--- a/sdm/libs/core/strategy.cpp
+++ b/sdm/libs/core/strategy.cpp
@@ -34,7 +34,7 @@
 Strategy::Strategy(ExtensionInterface *extension_intf, DisplayType type,
                    const HWResourceInfo &hw_resource_info, const HWPanelInfo &hw_panel_info)
   : extension_intf_(extension_intf), strategy_intf_(NULL), partial_update_intf_(NULL),
-    display_type_(type),hw_resource_info_(hw_resource_info), hw_panel_info_(hw_panel_info),
+    display_type_(type), hw_resource_info_(hw_resource_info), hw_panel_info_(hw_panel_info),
     hw_layers_info_(NULL), fb_layer_index_(0), extn_start_success_(false), tried_default_(false) {
 }
 
diff --git a/sdm/libs/hwc/hwc_display.cpp b/sdm/libs/hwc/hwc_display.cpp
index 0278c90..ef24854 100644
--- a/sdm/libs/hwc/hwc_display.cpp
+++ b/sdm/libs/hwc/hwc_display.cpp
@@ -409,7 +409,11 @@
 
     layer.plane_alpha = hwc_layer.planeAlpha;
     layer.flags.skip = ((hwc_layer.flags & HWC_SKIP_LAYER) > 0);
-    layer.flags.updating = (layer_stack_cache_.layer_cache[i].handle != hwc_layer.handle);
+    if (num_hw_layers <= kMaxLayerCount) {
+      layer.flags.updating = (layer_stack_cache_.layer_cache[i].handle != hwc_layer.handle);
+    } else {
+      layer.flags.updating = true;
+    }
 
     if (hwc_layer.flags & HWC_SCREENSHOT_ANIMATOR_LAYER) {
       layer_stack_.flags.animating = true;
@@ -617,6 +621,10 @@
 void HWCDisplay::CacheLayerStackInfo(hwc_display_contents_1_t *content_list) {
   uint32_t layer_count = layer_stack_.layer_count;
 
+  if (layer_count > kMaxLayerCount) {
+    return;
+  }
+
   for (uint32_t i = 0; i < layer_count; i++) {
     Layer &layer = layer_stack_.layers[i];