fixed unsafe usage of malloc() pointed out by jtsiomb.
[freeglut] / src / mswin / fg_spaceball_mswin.c
index 5a0d85d..277b648 100644 (file)
@@ -37,6 +37,7 @@
  */
 
 #include <GL/freeglut.h>
+#include <stdlib.h>
 #include "../fg_internal.h"
 
 enum {
@@ -53,7 +54,7 @@ RAWINPUTDEVICE __fgSpaceball = { 0x01, 0x08, 0x00, 0x00 };
 void fgPlatformInitializeSpaceball(void)
 {
        HWND hwnd;
-    sball_initialized = 1;
+       sball_initialized = 1;
        if (!fgStructure.CurrentWindow)
        {
                sball_initialized = 0;
@@ -121,7 +122,7 @@ void fgSpaceballHandleWinEvent(HWND hwnd, WPARAM wParam, LPARAM lParam)
        if (res == -1)
                return;
 
-       rawInputBuffer = (BYTE*)malloc(size);
+       rawInputBuffer = malloc(size * sizeof *rawInputBuffer);
        pRawInput = (PRAWINPUT)rawInputBuffer;
 
        res = GetRawInputData(hRawInput, RID_INPUT, pRawInput, &size, sizeof(RAWINPUTHEADER));
@@ -188,4 +189,4 @@ void fgSpaceballHandleWinEvent(HWND hwnd, WPARAM wParam, LPARAM lParam)
                        __fgSpaceKeystate = dwKeystate;
                }
        }
-}
\ No newline at end of file
+}