aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoman Kiryanov <rkir@google.com>2019-04-24 17:51:13 -0700
committerRoman Kiryanov <rkir@google.com>2019-04-26 16:54:44 -0700
commit7a820ebf3f97eb3e3f090699cbc4f9542d52faad (patch)
treed268c99962e61782e3c17004612cf84c06c08f2d
parentea5f0f11deca60ae61418e627c14340680967ac0 (diff)
downloaddevice_generic_goldfish-opengl-7a820ebf3f97eb3e3f090699cbc4f9542d52faad.tar.gz
device_generic_goldfish-opengl-7a820ebf3f97eb3e3f090699cbc4f9542d52faad.tar.bz2
device_generic_goldfish-opengl-7a820ebf3f97eb3e3f090699cbc4f9542d52faad.zip
Fix vk_append_struct to add elements after the last one
This also limits list's length to some random number to crash if the struct chain has a loop. Bug: 131181334 Test: make Change-Id: I265b0c69e528154917f031799b37014502fd4ec3 Merged-In: I5ae17ce129aba820b98f999208802c9135cbd8b8 Signed-off-by: Roman Kiryanov <rkir@google.com>
-rw-r--r--system/vulkan_enc/vk_util.h24
1 files changed, 21 insertions, 3 deletions
diff --git a/system/vulkan_enc/vk_util.h b/system/vulkan_enc/vk_util.h
index 0c7f4b98..da394f4e 100644
--- a/system/vulkan_enc/vk_util.h
+++ b/system/vulkan_enc/vk_util.h
@@ -26,6 +26,7 @@
/* common inlines and macros for vulkan drivers */
#include <vulkan/vulkan.h>
+#include <stdlib.h>
struct vk_struct_common {
VkStructureType sType;
@@ -215,11 +216,28 @@ vk_init_struct_chain(vk_struct_common* start)
}
static inline vk_struct_common*
+vk_last_struct_chain(vk_struct_common* i)
+{
+ for (int n = 1000000; n > 0; --n) {
+ vk_struct_common* next = i->pNext;
+ if (next) {
+ i = next;
+ } else {
+ return i;
+ }
+ }
+
+ ::abort(); // crash on loops in the chain
+ return NULL;
+}
+
+static inline vk_struct_common*
vk_append_struct(vk_struct_common* current, vk_struct_common* next)
{
- current->pNext = next;
- next->pNext = nullptr;
- return next;
+ vk_struct_common* last = vk_last_struct_chain(current);
+ last->pNext = next;
+ next->pNext = nullptr;
+ return current;
}
#endif /* VK_UTIL_H */