From 12a695696ddfe395e1e94e7eaceec7b40046d93d Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 4 May 2016 16:28:08 +0200 Subject: [PATCH] Add validation of size limit and aspect ratio args --- include/GLFW/glfw3.h | 7 +++++-- src/window.c | 19 +++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index cedecfcb..06c722ca 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -2056,6 +2056,9 @@ GLFWAPI void glfwGetWindowSize(GLFWwindow* window, int* width, int* height); * The size limits are applied immediately to a windowed mode window and may * cause it to be resized. * + * The maximum dimensions must be greater than or equal to the minimum + * dimensions and all must be greater than or equal to zero. + * * @param[in] window The window to set limits for. * @param[in] minwidth The minimum width, in screen coordinates, of the client * area, or `GLFW_DONT_CARE`. @@ -2066,8 +2069,8 @@ GLFWAPI void glfwGetWindowSize(GLFWwindow* window, int* width, int* height); * @param[in] maxheight The maximum height, in screen coordinates, of the * client area, or `GLFW_DONT_CARE`. * - * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref - * GLFW_PLATFORM_ERROR. + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref + * GLFW_INVALID_VALUE and @ref GLFW_PLATFORM_ERROR. * * @remark If you set size limits and an aspect ratio that conflict, the * results are undefined. diff --git a/src/window.c b/src/window.c index 104c703e..fee08b25 100644 --- a/src/window.c +++ b/src/window.c @@ -521,6 +521,13 @@ GLFWAPI void glfwSetWindowSizeLimits(GLFWwindow* handle, _GLFW_REQUIRE_INIT(); + if (minwidth < 0 || minheight < 0 || + maxwidth < minwidth || maxheight < minheight) + { + _glfwInputError(GLFW_INVALID_VALUE, "Invalid window size limits"); + return; + } + window->minwidth = minwidth; window->minheight = minheight; window->maxwidth = maxwidth; @@ -541,18 +548,18 @@ GLFWAPI void glfwSetWindowAspectRatio(GLFWwindow* handle, int numer, int denom) _GLFW_REQUIRE_INIT(); + if (numer <= 0 || denom <= 0) + { + _glfwInputError(GLFW_INVALID_VALUE, "Invalid window aspect ratio"); + return; + } + window->numer = numer; window->denom = denom; if (window->monitor || !window->resizable) return; - if (!denom) - { - _glfwInputError(GLFW_INVALID_VALUE, "Denominator cannot be zero"); - return; - } - _glfwPlatformSetWindowAspectRatio(window, numer, denom); }