From 0ebdad53e81ccae31395c2855d641f034a7ad506 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 31 Jan 2016 17:56:36 +0100 Subject: [PATCH] Add asserts for public API pointer parameters --- src/context.c | 6 ++++++ src/input.c | 34 ++++++++++++++++++++++++++++++++++ src/monitor.c | 13 +++++++++++++ src/window.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+) diff --git a/src/context.c b/src/context.c index 3da19864..455beeab 100644 --- a/src/context.c +++ b/src/context.c @@ -27,6 +27,7 @@ #include "internal.h" +#include #include #include #include @@ -566,6 +567,7 @@ GLFWAPI GLFWwindow* glfwGetCurrentContext(void) GLFWAPI void glfwSwapBuffers(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); _GLFW_REQUIRE_INIT(); @@ -595,6 +597,8 @@ GLFWAPI int glfwExtensionSupported(const char* extension) { _GLFWwindow* window; + assert(extension); + _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); window = _glfwPlatformGetCurrentContext(); @@ -657,6 +661,8 @@ GLFWAPI int glfwExtensionSupported(const char* extension) GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname) { + assert(procname); + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); if (!_glfwPlatformGetCurrentContext()) diff --git a/src/input.c b/src/input.c index db33ff72..01184c32 100644 --- a/src/input.c +++ b/src/input.c @@ -27,6 +27,7 @@ #include "internal.h" +#include #include // Internal key state used for sticky keys @@ -239,6 +240,7 @@ GLFWbool _glfwIsPrintable(int key) GLFWAPI int glfwGetInputMode(GLFWwindow* handle, int mode) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); _GLFW_REQUIRE_INIT_OR_RETURN(0); @@ -259,6 +261,7 @@ GLFWAPI int glfwGetInputMode(GLFWwindow* handle, int mode) GLFWAPI void glfwSetInputMode(GLFWwindow* handle, int mode, int value) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); _GLFW_REQUIRE_INIT(); @@ -288,6 +291,7 @@ GLFWAPI const char* glfwGetKeyName(int key, int scancode) GLFWAPI int glfwGetKey(GLFWwindow* handle, int key) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_RELEASE); @@ -310,6 +314,7 @@ GLFWAPI int glfwGetKey(GLFWwindow* handle, int key) GLFWAPI int glfwGetMouseButton(GLFWwindow* handle, int button) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_RELEASE); @@ -333,6 +338,7 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow* handle, int button) GLFWAPI void glfwGetCursorPos(GLFWwindow* handle, double* xpos, double* ypos) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); if (xpos) *xpos = 0; @@ -355,6 +361,7 @@ GLFWAPI void glfwGetCursorPos(GLFWwindow* handle, double* xpos, double* ypos) GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, double xpos, double ypos) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); _GLFW_REQUIRE_INIT(); @@ -378,6 +385,8 @@ GLFWAPI GLFWcursor* glfwCreateCursor(const GLFWimage* image, int xhot, int yhot) { _GLFWcursor* cursor; + assert(image); + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); cursor = calloc(1, sizeof(_GLFWcursor)); @@ -462,6 +471,7 @@ GLFWAPI void glfwSetCursor(GLFWwindow* windowHandle, GLFWcursor* cursorHandle) { _GLFWwindow* window = (_GLFWwindow*) windowHandle; _GLFWcursor* cursor = (_GLFWcursor*) cursorHandle; + assert(window); _GLFW_REQUIRE_INIT(); @@ -473,6 +483,8 @@ GLFWAPI void glfwSetCursor(GLFWwindow* windowHandle, GLFWcursor* cursorHandle) GLFWAPI GLFWkeyfun glfwSetKeyCallback(GLFWwindow* handle, GLFWkeyfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP_POINTERS(window->callbacks.key, cbfun); return cbfun; @@ -481,6 +493,8 @@ GLFWAPI GLFWkeyfun glfwSetKeyCallback(GLFWwindow* handle, GLFWkeyfun cbfun) GLFWAPI GLFWcharfun glfwSetCharCallback(GLFWwindow* handle, GLFWcharfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP_POINTERS(window->callbacks.character, cbfun); return cbfun; @@ -489,6 +503,8 @@ GLFWAPI GLFWcharfun glfwSetCharCallback(GLFWwindow* handle, GLFWcharfun cbfun) GLFWAPI GLFWcharmodsfun glfwSetCharModsCallback(GLFWwindow* handle, GLFWcharmodsfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP_POINTERS(window->callbacks.charmods, cbfun); return cbfun; @@ -498,6 +514,8 @@ GLFWAPI GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* handle, GLFWmousebuttonfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP_POINTERS(window->callbacks.mouseButton, cbfun); return cbfun; @@ -507,6 +525,8 @@ GLFWAPI GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow* handle, GLFWcursorposfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP_POINTERS(window->callbacks.cursorPos, cbfun); return cbfun; @@ -516,6 +536,8 @@ GLFWAPI GLFWcursorenterfun glfwSetCursorEnterCallback(GLFWwindow* handle, GLFWcursorenterfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP_POINTERS(window->callbacks.cursorEnter, cbfun); return cbfun; @@ -525,6 +547,8 @@ GLFWAPI GLFWscrollfun glfwSetScrollCallback(GLFWwindow* handle, GLFWscrollfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP_POINTERS(window->callbacks.scroll, cbfun); return cbfun; @@ -533,6 +557,8 @@ GLFWAPI GLFWscrollfun glfwSetScrollCallback(GLFWwindow* handle, GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* handle, GLFWdropfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP_POINTERS(window->callbacks.drop, cbfun); return cbfun; @@ -553,6 +579,7 @@ GLFWAPI int glfwJoystickPresent(int joy) GLFWAPI const float* glfwGetJoystickAxes(int joy, int* count) { + assert(count); *count = 0; _GLFW_REQUIRE_INIT_OR_RETURN(NULL); @@ -568,6 +595,7 @@ GLFWAPI const float* glfwGetJoystickAxes(int joy, int* count) GLFWAPI const unsigned char* glfwGetJoystickButtons(int joy, int* count) { + assert(count); *count = 0; _GLFW_REQUIRE_INIT_OR_RETURN(NULL); @@ -597,6 +625,10 @@ GLFWAPI const char* glfwGetJoystickName(int joy) GLFWAPI void glfwSetClipboardString(GLFWwindow* handle, const char* string) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + + assert(string); + _GLFW_REQUIRE_INIT(); _glfwPlatformSetClipboardString(window, string); } @@ -604,6 +636,8 @@ GLFWAPI void glfwSetClipboardString(GLFWwindow* handle, const char* string) GLFWAPI const char* glfwGetClipboardString(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); return _glfwPlatformGetClipboardString(window); } diff --git a/src/monitor.c b/src/monitor.c index f9ab7b0d..1aebf0ba 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -27,6 +27,7 @@ #include "internal.h" +#include #include #include #include @@ -293,6 +294,7 @@ void _glfwSplitBPP(int bpp, int* red, int* green, int* blue) GLFWAPI GLFWmonitor** glfwGetMonitors(int* count) { + assert(count); *count = 0; _GLFW_REQUIRE_INIT_OR_RETURN(NULL); @@ -314,6 +316,7 @@ GLFWAPI GLFWmonitor* glfwGetPrimaryMonitor(void) GLFWAPI void glfwGetMonitorPos(GLFWmonitor* handle, int* xpos, int* ypos) { _GLFWmonitor* monitor = (_GLFWmonitor*) handle; + assert(monitor); if (xpos) *xpos = 0; @@ -328,6 +331,7 @@ GLFWAPI void glfwGetMonitorPos(GLFWmonitor* handle, int* xpos, int* ypos) GLFWAPI void glfwGetMonitorPhysicalSize(GLFWmonitor* handle, int* widthMM, int* heightMM) { _GLFWmonitor* monitor = (_GLFWmonitor*) handle; + assert(monitor); if (widthMM) *widthMM = 0; @@ -345,6 +349,8 @@ GLFWAPI void glfwGetMonitorPhysicalSize(GLFWmonitor* handle, int* widthMM, int* GLFWAPI const char* glfwGetMonitorName(GLFWmonitor* handle) { _GLFWmonitor* monitor = (_GLFWmonitor*) handle; + assert(monitor); + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); return monitor->name; } @@ -359,7 +365,9 @@ GLFWAPI GLFWmonitorfun glfwSetMonitorCallback(GLFWmonitorfun cbfun) GLFWAPI const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* handle, int* count) { _GLFWmonitor* monitor = (_GLFWmonitor*) handle; + assert(monitor); + assert(count); *count = 0; _GLFW_REQUIRE_INIT_OR_RETURN(NULL); @@ -374,6 +382,7 @@ GLFWAPI const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* handle, int* count) GLFWAPI const GLFWvidmode* glfwGetVideoMode(GLFWmonitor* handle) { _GLFWmonitor* monitor = (_GLFWmonitor*) handle; + assert(monitor); _GLFW_REQUIRE_INIT_OR_RETURN(NULL); @@ -422,6 +431,7 @@ GLFWAPI void glfwSetGamma(GLFWmonitor* handle, float gamma) GLFWAPI const GLFWgammaramp* glfwGetGammaRamp(GLFWmonitor* handle) { _GLFWmonitor* monitor = (_GLFWmonitor*) handle; + assert(monitor); _GLFW_REQUIRE_INIT_OR_RETURN(NULL); @@ -434,6 +444,9 @@ GLFWAPI const GLFWgammaramp* glfwGetGammaRamp(GLFWmonitor* handle) GLFWAPI void glfwSetGammaRamp(GLFWmonitor* handle, const GLFWgammaramp* ramp) { _GLFWmonitor* monitor = (_GLFWmonitor*) handle; + assert(monitor); + + assert(ramp); _GLFW_REQUIRE_INIT(); diff --git a/src/window.c b/src/window.c index eff61be2..f0063e35 100644 --- a/src/window.c +++ b/src/window.c @@ -28,6 +28,7 @@ #include "internal.h" +#include #include #include @@ -124,6 +125,8 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, _GLFWwindow* window; _GLFWwindow* previous; + assert(title); + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); if (width <= 0 || height <= 0) @@ -415,6 +418,8 @@ GLFWAPI void glfwDestroyWindow(GLFWwindow* handle) GLFWAPI int glfwWindowShouldClose(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + _GLFW_REQUIRE_INIT_OR_RETURN(0); return window->closed; } @@ -422,6 +427,8 @@ GLFWAPI int glfwWindowShouldClose(GLFWwindow* handle) GLFWAPI void glfwSetWindowShouldClose(GLFWwindow* handle, int value) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + _GLFW_REQUIRE_INIT(); window->closed = value; } @@ -429,6 +436,10 @@ GLFWAPI void glfwSetWindowShouldClose(GLFWwindow* handle, int value) GLFWAPI void glfwSetWindowTitle(GLFWwindow* handle, const char* title) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + + assert(title); + _GLFW_REQUIRE_INIT(); _glfwPlatformSetWindowTitle(window, title); } @@ -436,6 +447,7 @@ GLFWAPI void glfwSetWindowTitle(GLFWwindow* handle, const char* title) GLFWAPI void glfwGetWindowPos(GLFWwindow* handle, int* xpos, int* ypos) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); if (xpos) *xpos = 0; @@ -449,6 +461,7 @@ GLFWAPI void glfwGetWindowPos(GLFWwindow* handle, int* xpos, int* ypos) GLFWAPI void glfwSetWindowPos(GLFWwindow* handle, int xpos, int ypos) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); _GLFW_REQUIRE_INIT(); @@ -465,6 +478,7 @@ GLFWAPI void glfwSetWindowPos(GLFWwindow* handle, int xpos, int ypos) GLFWAPI void glfwGetWindowSize(GLFWwindow* handle, int* width, int* height) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); if (width) *width = 0; @@ -478,6 +492,7 @@ GLFWAPI void glfwGetWindowSize(GLFWwindow* handle, int* width, int* height) GLFWAPI void glfwSetWindowSize(GLFWwindow* handle, int width, int height) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); _GLFW_REQUIRE_INIT(); @@ -495,6 +510,7 @@ GLFWAPI void glfwSetWindowSizeLimits(GLFWwindow* handle, int maxwidth, int maxheight) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); _GLFW_REQUIRE_INIT(); @@ -509,6 +525,7 @@ GLFWAPI void glfwSetWindowSizeLimits(GLFWwindow* handle, GLFWAPI void glfwSetWindowAspectRatio(GLFWwindow* handle, int numer, int denom) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); _GLFW_REQUIRE_INIT(); @@ -527,6 +544,7 @@ GLFWAPI void glfwSetWindowAspectRatio(GLFWwindow* handle, int numer, int denom) GLFWAPI void glfwGetFramebufferSize(GLFWwindow* handle, int* width, int* height) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); if (width) *width = 0; @@ -542,6 +560,7 @@ GLFWAPI void glfwGetWindowFrameSize(GLFWwindow* handle, int* right, int* bottom) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); if (left) *left = 0; @@ -559,6 +578,8 @@ GLFWAPI void glfwGetWindowFrameSize(GLFWwindow* handle, GLFWAPI void glfwIconifyWindow(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + _GLFW_REQUIRE_INIT(); _glfwPlatformIconifyWindow(window); } @@ -566,6 +587,8 @@ GLFWAPI void glfwIconifyWindow(GLFWwindow* handle) GLFWAPI void glfwRestoreWindow(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + _GLFW_REQUIRE_INIT(); _glfwPlatformRestoreWindow(window); } @@ -573,6 +596,7 @@ GLFWAPI void glfwRestoreWindow(GLFWwindow* handle) GLFWAPI void glfwShowWindow(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); _GLFW_REQUIRE_INIT(); @@ -585,6 +609,7 @@ GLFWAPI void glfwShowWindow(GLFWwindow* handle) GLFWAPI void glfwHideWindow(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); _GLFW_REQUIRE_INIT(); @@ -597,6 +622,7 @@ GLFWAPI void glfwHideWindow(GLFWwindow* handle) GLFWAPI int glfwGetWindowAttrib(GLFWwindow* handle, int attrib) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); _GLFW_REQUIRE_INIT_OR_RETURN(0); @@ -643,6 +669,8 @@ GLFWAPI int glfwGetWindowAttrib(GLFWwindow* handle, int attrib) GLFWAPI GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); return (GLFWmonitor*) window->monitor; } @@ -650,6 +678,8 @@ GLFWAPI GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* handle) GLFWAPI void glfwSetWindowUserPointer(GLFWwindow* handle, void* pointer) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + _GLFW_REQUIRE_INIT(); window->userPointer = pointer; } @@ -657,6 +687,8 @@ GLFWAPI void glfwSetWindowUserPointer(GLFWwindow* handle, void* pointer) GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow* handle) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); return window->userPointer; } @@ -665,6 +697,8 @@ GLFWAPI GLFWwindowposfun glfwSetWindowPosCallback(GLFWwindow* handle, GLFWwindowposfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP_POINTERS(window->callbacks.pos, cbfun); return cbfun; @@ -674,6 +708,8 @@ GLFWAPI GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* handle, GLFWwindowsizefun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP_POINTERS(window->callbacks.size, cbfun); return cbfun; @@ -683,6 +719,8 @@ GLFWAPI GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* handle, GLFWwindowclosefun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP_POINTERS(window->callbacks.close, cbfun); return cbfun; @@ -692,6 +730,8 @@ GLFWAPI GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* handle, GLFWwindowrefreshfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP_POINTERS(window->callbacks.refresh, cbfun); return cbfun; @@ -701,6 +741,8 @@ GLFWAPI GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* handle, GLFWwindowfocusfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP_POINTERS(window->callbacks.focus, cbfun); return cbfun; @@ -710,6 +752,8 @@ GLFWAPI GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* handle, GLFWwindowiconifyfun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP_POINTERS(window->callbacks.iconify, cbfun); return cbfun; @@ -719,6 +763,8 @@ GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* handle GLFWframebuffersizefun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle; + assert(window); + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_SWAP_POINTERS(window->callbacks.fbsize, cbfun); return cbfun;