diff --git a/src/cocoa_gamma.c b/src/cocoa_gamma.c index 9e2e7b1d..fb3d2f9d 100644 --- a/src/cocoa_gamma.c +++ b/src/cocoa_gamma.c @@ -43,7 +43,7 @@ void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) { uint32_t i, size = CGDisplayGammaTableCapacity(monitor->ns.displayID); - CGGammaValue* values = (CGGammaValue*) malloc(size * 3 * sizeof(CGGammaValue)); + CGGammaValue* values = (CGGammaValue*) calloc(size * 3, sizeof(CGGammaValue)); CGGetDisplayTransferByTable(monitor->ns.displayID, size, @@ -67,7 +67,7 @@ void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) { int i; - CGGammaValue* values = (CGGammaValue*) malloc(ramp->size * 3 * sizeof(CGGammaValue)); + CGGammaValue* values = (CGGammaValue*) calloc(ramp->size * 3, sizeof(CGGammaValue)); for (i = 0; i < ramp->size; i++) { diff --git a/src/cocoa_joystick.m b/src/cocoa_joystick.m index 63d253d8..c4804309 100644 --- a/src/cocoa_joystick.m +++ b/src/cocoa_joystick.m @@ -113,7 +113,7 @@ static void addJoystickElement(_GLFWjoy* joystick, CFTypeRef elementRef) { long number; CFTypeRef numberRef; - _GLFWjoyelement* element = (_GLFWjoyelement*) malloc(sizeof(_GLFWjoyelement)); + _GLFWjoyelement* element = (_GLFWjoyelement*) calloc(1, sizeof(_GLFWjoyelement)); CFArrayAppendValue(elementsArray, element); diff --git a/src/cocoa_monitor.m b/src/cocoa_monitor.m index 34224c3b..79e22d3b 100644 --- a/src/cocoa_monitor.m +++ b/src/cocoa_monitor.m @@ -58,7 +58,7 @@ static const char* getDisplayName(CGDirectDisplayID displayID) size = CFStringGetMaximumSizeForEncoding(CFStringGetLength(value), kCFStringEncodingUTF8); - name = (char*) malloc(size + 1); + name = (char*) calloc(size + 1, sizeof(char)); CFStringGetCString(value, name, size, kCFStringEncodingUTF8); CFRelease(info); @@ -341,7 +341,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) modes = CGDisplayCopyAllDisplayModes(monitor->ns.displayID, NULL); count = CFArrayGetCount(modes); - result = (GLFWvidmode*) malloc(sizeof(GLFWvidmode) * count); + result = (GLFWvidmode*) calloc(count, sizeof(GLFWvidmode)); *found = 0; for (i = 0; i < count; i++) diff --git a/src/gamma.c b/src/gamma.c index 781539bf..2ee83a9b 100644 --- a/src/gamma.c +++ b/src/gamma.c @@ -44,9 +44,9 @@ void _glfwAllocGammaRamp(GLFWgammaramp* ramp, unsigned int size) { - ramp->red = (unsigned short*) malloc(size * sizeof(unsigned short)); - ramp->green = (unsigned short*) malloc(size * sizeof(unsigned short)); - ramp->blue = (unsigned short*) malloc(size * sizeof(unsigned short)); + ramp->red = (unsigned short*) calloc(size, sizeof(unsigned short)); + ramp->green = (unsigned short*) calloc(size, sizeof(unsigned short)); + ramp->blue = (unsigned short*) calloc(size, sizeof(unsigned short)); ramp->size = size; } diff --git a/src/win32_init.c b/src/win32_init.c index c2c80186..188522df 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -146,7 +146,7 @@ WCHAR* _glfwCreateWideStringFromUTF8(const char* source) if (!length) return NULL; - target = (WCHAR*) malloc(sizeof(WCHAR) * (length + 1)); + target = (WCHAR*) calloc(length + 1, sizeof(WCHAR)); if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, length + 1)) { @@ -168,7 +168,7 @@ char* _glfwCreateUTF8FromWideString(const WCHAR* source) if (!length) return NULL; - target = (char*) malloc(length + 1); + target = (char*) calloc(length + 1, sizeof(char)); if (!WideCharToMultiByte(CP_UTF8, 0, source, -1, target, length + 1, NULL, NULL)) { diff --git a/src/x11_monitor.c b/src/x11_monitor.c index 72de2d78..c6549ced 100644 --- a/src/x11_monitor.c +++ b/src/x11_monitor.c @@ -312,7 +312,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) sr = XRRGetScreenResources(_glfw.x11.display, _glfw.x11.root); oi = XRRGetOutputInfo(_glfw.x11.display, sr, monitor->x11.output); - result = (GLFWvidmode*) malloc(sizeof(GLFWvidmode) * oi->nmode); + result = (GLFWvidmode*) calloc(oi->nmode, sizeof(GLFWvidmode)); for (i = 0; i < oi->nmode; i++) { @@ -354,7 +354,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found) { *found = 1; - result = (GLFWvidmode*) malloc(sizeof(GLFWvidmode)); + result = (GLFWvidmode*) calloc(1, sizeof(GLFWvidmode)); result[0].width = DisplayWidth(_glfw.x11.display, _glfw.x11.screen); result[0].height = DisplayHeight(_glfw.x11.display, _glfw.x11.screen);