This commit is contained in:
Brett R. Toomey 2015-07-22 09:02:33 +00:00
commit 833d8f5cc9
19 changed files with 240 additions and 1 deletions

View File

@ -67,6 +67,15 @@ static char* getDisplayName(CGDirectDisplayID displayID)
size = CFStringGetMaximumSizeForEncoding(CFStringGetLength(value),
kCFStringEncodingUTF8);
name = calloc(size + 1, sizeof(char));
if (name == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"Cocoa: Failed to allocate name");
CFRelease(info);
return strdup("Unknown");
}
CFStringGetCString(value, name, size, kCFStringEncodingUTF8);
CFRelease(info);
@ -253,7 +262,22 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
CGGetOnlineDisplayList(0, NULL, &displayCount);
displays = calloc(displayCount, sizeof(CGDirectDisplayID));
if (displays == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"Failed to allocate displays");
return NULL;
}
monitors = calloc(displayCount, sizeof(_GLFWmonitor*));
if (monitors == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"Failed to allocate monitors");
free(displays);
return NULL;
}
CGGetOnlineDisplayList(displayCount, displays, &displayCount);
NSArray* screens = [NSScreen screens];

View File

@ -613,6 +613,11 @@ static int translateKey(unsigned int key)
{
NSEnumerator* e = [files objectEnumerator];
char** paths = calloc(count, sizeof(char*));
if (paths == NULL)
{
return NO;
}
int i;
for (i = 0; i < count; i++)

View File

@ -101,9 +101,25 @@ static GLboolean chooseFBConfigs(const _GLFWctxconfig* ctxconfig,
}
nativeConfigs = calloc(nativeCount, sizeof(EGLConfig));
if (nativeConfigs == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"EGL: Failed to allocate native configs");
return GL_FALSE;
}
eglGetConfigs(_glfw.egl.display, nativeConfigs, nativeCount, &nativeCount);
usableConfigs = calloc(nativeCount, sizeof(_GLFWfbconfig));
if (usableConfigs == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"EGL: Failed to allocate usable configs");
free(nativeConfigs);
return GL_FALSE;
}
usableCount = 0;
for (i = 0; i < nativeCount; i++)

View File

@ -72,6 +72,13 @@ static GLboolean chooseFBConfig(const _GLFWfbconfig* desired, GLXFBConfig* resul
}
usableConfigs = calloc(nativeCount, sizeof(_GLFWfbconfig));
if (usableConfigs == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"GLX: Failed to allocate usable configs");
return GL_FALSE;
}
usableCount = 0;
for (i = 0; i < nativeCount; i++)

View File

@ -366,6 +366,13 @@ GLFWAPI GLFWcursor* glfwCreateCursor(const GLFWimage* image, int xhot, int yhot)
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
cursor = calloc(1, sizeof(_GLFWcursor));
if (cursor == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"Failed to allocate cursor");
return NULL;
}
cursor->next = _glfw.cursorListHead;
_glfw.cursorListHead = cursor;
@ -396,6 +403,12 @@ GLFWAPI GLFWcursor* glfwCreateStandardCursor(int shape)
}
cursor = calloc(1, sizeof(_GLFWcursor));
if (cursor == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"Failed to allocate cursor");
return NULL;
}
cursor->next = _glfw.cursorListHead;
_glfw.cursorListHead = cursor;

View File

@ -110,6 +110,12 @@ static void addJoystickElement(_GLFWjoydevice* joystick,
if (elementsArray)
{
_GLFWjoyelement* element = calloc(1, sizeof(_GLFWjoyelement));
if (element == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"IOKit: Failed to allocate element");
return;
}
CFArrayAppendValue(elementsArray, element);
@ -313,8 +319,25 @@ static void matchCallback(void* context,
joystick->axes = calloc(CFArrayGetCount(joystick->axisElements),
sizeof(float));
if (joystick->axes == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"IOKit: Failed to allocate axes");
joystick->present = GL_FALSE;
return;
}
joystick->buttons = calloc(CFArrayGetCount(joystick->buttonElements) +
CFArrayGetCount(joystick->hatElements) * 4, 1);
if (joystick->buttons == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"IOKit: Failed to allocate buttons");
joystick->present = GL_FALSE;
return;
}
}
// Callback for user-initiated joystick removal

View File

@ -98,8 +98,23 @@ static void openJoystickDevice(const char* path)
_glfw.linux_js.js[joy].buttonCount = (int) buttonCount;
_glfw.linux_js.js[joy].axes = calloc(axisCount, sizeof(float));
_glfw.linux_js.js[joy].buttons = calloc(buttonCount, 1);
if (_glfw.linux_js.js[joy].axes == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"Linux: Failed to allocate joystix axes");
close(fd);
return;
}
_glfw.linux_js.js[joy].buttons = calloc(buttonCount, 1);
if (_glfw.linux_js.js[joy].buttons == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"Linux: Failed to allocate joystick buttons");
close(fd);
return;
}
_glfw.linux_js.js[joy].present = GL_TRUE;
#endif // __linux__
}

View File

@ -59,6 +59,13 @@ int _glfwPlatformInit(void)
_glfwInitJoysticks();
_glfw.mir.event_queue = calloc(1, sizeof(EventQueue));
if (_glfw.mir.event_queue == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"Mir: Failed to allocate event queue");
return GL_FALSE;
}
_glfwInitEventQueue(_glfw.mir.event_queue);
error = pthread_mutex_init(&_glfw.mir.event_mutex, NULL);

View File

@ -100,6 +100,14 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
continue;
modes = calloc(out->num_modes, sizeof(GLFWvidmode));
if (modes == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"Mir: Failed to allocate modes");
mir_display_config_destroy(displayConfig);
return NULL;
}
for (*found = 0; *found < out->num_modes; (*found)++)
{

View File

@ -52,7 +52,22 @@ static int emptyEventQueue(EventQueue* queue)
static EventNode* newEventNode(MirEvent const* event, _GLFWwindow* context)
{
EventNode* new_node = calloc(1, sizeof(EventNode));
if (new_node == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"Mir: Failed to allocate new node");
return NULL;
}
new_node->event = calloc(1, sizeof(MirEvent));
if (new_node->event == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"Mir: failed to allocate new node event");
free(new_node);
return NULL;
}
new_node->window = context;
memcpy(new_node->event, event, sizeof(MirEvent));

View File

@ -166,6 +166,13 @@ void _glfwInputMonitorChange(void)
_GLFWmonitor* _glfwAllocMonitor(const char* name, int widthMM, int heightMM)
{
_GLFWmonitor* monitor = calloc(1, sizeof(_GLFWmonitor));
if (monitor == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"Failed to allocate monitor");
return NULL;
}
monitor->name = strdup(name);
monitor->widthMM = widthMM;
monitor->heightMM = heightMM;
@ -191,6 +198,15 @@ void _glfwAllocGammaArrays(GLFWgammaramp* ramp, unsigned int size)
ramp->red = calloc(size, sizeof(unsigned short));
ramp->green = calloc(size, sizeof(unsigned short));
ramp->blue = calloc(size, sizeof(unsigned short));
if (ramp->red == NULL ||
ramp->green == NULL ||
ramp->blue == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"Failed to allocate gamma arrays");
}
ramp->size = size;
}

View File

@ -125,6 +125,13 @@ static GLboolean choosePixelFormat(_GLFWwindow* window,
}
usableConfigs = calloc(nativeCount, sizeof(_GLFWfbconfig));
if (usableConfigs == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"WGL: Failed to allocate usable configs");
return GL_FALSE;
}
usableCount = 0;
for (i = 0; i < nativeCount; i++)

View File

@ -284,6 +284,12 @@ WCHAR* _glfwCreateWideStringFromUTF8(const char* source)
return NULL;
target = calloc(length, sizeof(WCHAR));
if (target == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"Win32 Init: Failed to allocate target");
return NULL;
}
if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, length))
{
@ -306,6 +312,12 @@ char* _glfwCreateUTF8FromWideString(const WCHAR* source)
return NULL;
target = calloc(length, sizeof(char));
if (target == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"Win32 Init: Failed to allocate target");
return NULL;
}
if (!WideCharToMultiByte(CP_UTF8, 0, source, -1, target, length, NULL, NULL))
{

View File

@ -602,6 +602,13 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
const int count = DragQueryFileW(hDrop, 0xffffffff, NULL, 0);
char** paths = calloc(count, sizeof(char*));
if (paths == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"Win32: Failed to allocate paths");
return 0;
}
// Move the mouse to the position of the drop
DragQueryPoint(hDrop, &pt);
@ -611,6 +618,13 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
{
const UINT length = DragQueryFileW(hDrop, i, NULL, 0);
WCHAR* buffer = calloc(length + 1, sizeof(WCHAR));
if (buffer == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"Win32: Failed to allocate buffer");
free(paths);
return 0;
}
DragQueryFileW(hDrop, i, buffer, length + 1);
paths[i] = _glfwCreateUTF8FromWideString(buffer);

View File

@ -154,6 +154,13 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
return NULL;
window = calloc(1, sizeof(_GLFWwindow));
if (window == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"Failed to allocate window");
return NULL;
}
window->next = _glfw.windowListHead;
_glfw.windowListHead = window;

View File

@ -555,6 +555,12 @@ int _glfwPlatformInit(void)
wl_registry_add_listener(_glfw.wl.registry, &registryListener, NULL);
_glfw.wl.monitors = calloc(4, sizeof(_GLFWmonitor*));
if (_glfw.wl.monitors == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"WL: Failed to allocate monitors");
return GL_FALSE;
}
_glfw.wl.monitorsSize = 4;
_glfw.wl.xkb.context = xkb_context_new(0);

View File

@ -140,6 +140,13 @@ void _glfwAddOutput(uint32_t name, uint32_t version)
}
monitor->wl.modes = calloc(4, sizeof(_GLFWvidmodeWayland));
if (monitor->wl.modes == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"Wayland: Failed to allocate modes");
return;
}
monitor->wl.modesSize = 4;
monitor->wl.output = output;
@ -151,6 +158,12 @@ void _glfwAddOutput(uint32_t name, uint32_t version)
int size = _glfw.wl.monitorsSize * 2;
monitors = realloc(monitors, size * sizeof(_GLFWmonitor*));
if (monitors == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"Wayland: Failed to allocate monitors");
return;
}
_glfw.wl.monitors = monitors;
_glfw.wl.monitorsSize = size;

View File

@ -215,6 +215,14 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
_glfw.x11.root);
monitors = calloc(sr->noutput, sizeof(_GLFWmonitor*));
if (monitors == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"X11: Failed to allocate monitors");
*count = 0;
return NULL;
}
if (_glfw.x11.xinerama.available)
screens = XineramaQueryScreens(_glfw.x11.display, &screenCount);
@ -294,6 +302,14 @@ _GLFWmonitor** _glfwPlatformGetMonitors(int* count)
if (!monitors)
{
monitors = calloc(1, sizeof(_GLFWmonitor*));
if (monitors == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"X11: Failed to allocate monitors");
*count = 0;
return NULL;
}
monitors[0] = _glfwAllocMonitor("Display",
DisplayWidthMM(_glfw.x11.display,
_glfw.x11.screen),

View File

@ -224,7 +224,22 @@ static char** parseUriList(char* text, int* count)
(*count)++;
char* path = calloc(strlen(line) + 1, 1);
if (path == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"X11: Failed to allocate path");
return NULL;
}
paths = realloc(paths, *count * sizeof(char*));
if (paths == NULL)
{
_glfwInputError(GLFW_OUT_OF_MEMORY,
"X11: Failed to allocate paths");
free(path);
return NULL;
}
paths[*count - 1] = path;
while (*line)