From 3817b4e1c57c22cc22a26973615090dee29685d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 23 Feb 2017 17:47:41 +0100 Subject: [PATCH] Add more assertions --- src/monitor.c | 5 +++++ src/vulkan.c | 7 +++++++ src/window.c | 11 +++++++++++ 3 files changed, 23 insertions(+) diff --git a/src/monitor.c b/src/monitor.c index 80712f33..4acecd58 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -363,6 +363,10 @@ GLFWAPI void glfwSetGamma(GLFWmonitor* handle, float gamma) int i; unsigned short values[256]; GLFWgammaramp ramp; + assert(handle != NULL); + assert(gamma == gamma); + assert(gamma >= 0.f); + assert(gamma <= FLT_MAX); _GLFW_REQUIRE_INIT(); @@ -414,6 +418,7 @@ GLFWAPI void glfwSetGammaRamp(GLFWmonitor* handle, const GLFWgammaramp* ramp) _GLFWmonitor* monitor = (_GLFWmonitor*) handle; assert(monitor != NULL); assert(ramp != NULL); + assert(ramp->size > 0); assert(ramp->red != NULL); assert(ramp->green != NULL); assert(ramp->blue != NULL); diff --git a/src/vulkan.c b/src/vulkan.c index 91ea2671..858a1e97 100644 --- a/src/vulkan.c +++ b/src/vulkan.c @@ -234,6 +234,8 @@ GLFWAPI int glfwVulkanSupported(void) GLFWAPI const char** glfwGetRequiredInstanceExtensions(uint32_t* count) { + assert(count != NULL); + *count = 0; _GLFW_REQUIRE_INIT_OR_RETURN(NULL); @@ -252,6 +254,7 @@ GLFWAPI GLFWvkproc glfwGetInstanceProcAddress(VkInstance instance, const char* procname) { GLFWvkproc proc; + assert(procname != NULL); _GLFW_REQUIRE_INIT_OR_RETURN(NULL); @@ -277,6 +280,9 @@ GLFWAPI int glfwGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily) { + assert(instance != VK_NULL_HANDLE); + assert(device != VK_NULL_HANDLE); + _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) @@ -300,6 +306,7 @@ GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, VkSurfaceKHR* surface) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(instance != VK_NULL_HANDLE); assert(window != NULL); assert(surface != NULL); diff --git a/src/window.c b/src/window.c index 88377307..023cb13f 100644 --- a/src/window.c +++ b/src/window.c @@ -130,6 +130,8 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, _GLFWwindow* previous; assert(title != NULL); + assert(width >= 0); + assert(height >= 0); _GLFW_REQUIRE_INIT_OR_RETURN(NULL); @@ -508,6 +510,8 @@ GLFWAPI void glfwSetWindowSize(GLFWwindow* handle, int width, int height) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); + assert(width >= 0); + assert(height >= 0); _GLFW_REQUIRE_INIT(); @@ -566,6 +570,8 @@ GLFWAPI void glfwSetWindowAspectRatio(GLFWwindow* handle, int numer, int denom) { _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); + assert(numer != 0); + assert(denom != 0); _GLFW_REQUIRE_INIT(); @@ -808,6 +814,8 @@ GLFWAPI void glfwSetWindowMonitor(GLFWwindow* wh, _GLFWwindow* window = (_GLFWwindow*) wh; _GLFWmonitor* monitor = (_GLFWmonitor*) mh; assert(window != NULL); + assert(width >= 0); + assert(height >= 0); _GLFW_REQUIRE_INIT(); @@ -961,6 +969,9 @@ GLFWAPI void glfwWaitEvents(void) GLFWAPI void glfwWaitEventsTimeout(double timeout) { _GLFW_REQUIRE_INIT(); + assert(timeout == timeout); + assert(timeout >= 0.0); + assert(timeout <= DBL_MAX); if (timeout != timeout || timeout < 0.0 || timeout > DBL_MAX) {