Fix undefined behavior

Fixes #950.
This commit is contained in:
Camilla Löwy
2017-02-16 05:23:10 +01:00
parent f69829f7b4
commit 980f955f6c
3 changed files with 24 additions and 13 deletions
+8 -5
View File
@@ -102,7 +102,7 @@ void _glfwPollMonitorsX11(void)
if (_glfw.x11.randr.available && !_glfw.x11.randr.monitorBroken)
{
int i, j, disconnectedCount, screenCount = 0;
_GLFWmonitor** disconnected;
_GLFWmonitor** disconnected = NULL;
XineramaScreenInfo* screens = NULL;
XRRScreenResources* sr = XRRGetScreenResourcesCurrent(_glfw.x11.display,
_glfw.x11.root);
@@ -113,10 +113,13 @@ void _glfwPollMonitorsX11(void)
screens = XineramaQueryScreens(_glfw.x11.display, &screenCount);
disconnectedCount = _glfw.monitorCount;
disconnected = calloc(_glfw.monitorCount, sizeof(_GLFWmonitor*));
memcpy(disconnected,
_glfw.monitors,
_glfw.monitorCount * sizeof(_GLFWmonitor*));
if (disconnectedCount)
{
disconnected = calloc(_glfw.monitorCount, sizeof(_GLFWmonitor*));
memcpy(disconnected,
_glfw.monitors,
_glfw.monitorCount * sizeof(_GLFWmonitor*));
}
for (i = 0; i < sr->noutput; i++)
{