libvulkan: Check for negative in signed -> unsigned conversion
Requested during security audit in bug 27118888.
Change-Id: Id82382258d2b6f8523b8af29f494dfc67100d190
diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp
index 5fefc62..7f944cf 100644
--- a/vulkan/libvulkan/swapchain.cpp
+++ b/vulkan/libvulkan/swapchain.cpp
@@ -511,16 +511,18 @@
return VK_ERROR_INITIALIZATION_FAILED;
}
- uint32_t min_undequeued_buffers;
- err = surface.window->query(
- surface.window.get(), NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS,
- reinterpret_cast<int*>(&min_undequeued_buffers));
- if (err != 0) {
+ int query_value;
+ err = surface.window->query(surface.window.get(),
+ NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS,
+ &query_value);
+ if (err != 0 || query_value < 0) {
// TODO(jessehall): Improve error reporting. Can we enumerate possible
// errors and translate them to valid Vulkan result codes?
- ALOGE("window->query failed: %s (%d)", strerror(-err), err);
+ ALOGE("window->query failed: %s (%d) value=%d", strerror(-err), err,
+ query_value);
return VK_ERROR_INITIALIZATION_FAILED;
}
+ uint32_t min_undequeued_buffers = static_cast<uint32_t>(query_value);
// The MIN_UNDEQUEUED_BUFFERS query doesn't know whether we'll be using
// async mode or not, and assumes not. But in async mode, the BufferQueue
// requires an extra undequeued buffer.