Commit 1084421ccab4fd5f11120c994bd9986b39e87e40

Gabriel Jacobo 2014-02-24T10:25:02

Zero out haptic linked list items on creation (thanks to Turo Lamminen for the report!)

diff --git a/src/haptic/darwin/SDL_syshaptic.c b/src/haptic/darwin/SDL_syshaptic.c
index 4a62e35..cb02054 100644
--- a/src/haptic/darwin/SDL_syshaptic.c
+++ b/src/haptic/darwin/SDL_syshaptic.c
@@ -237,7 +237,7 @@ MacHaptic_MaybeAddDevice( io_object_t device )
         }
     }
 
-    item = (SDL_hapticlist_item *)SDL_malloc( sizeof(SDL_hapticlist_item));
+    item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
     if (item == NULL) {
         return SDL_SetError("Could not allocate haptic storage");
     }
@@ -248,7 +248,6 @@ MacHaptic_MaybeAddDevice( io_object_t device )
     /* Set basic device data. */
     HIDGetDeviceProduct(device, item->name);
     item->dev = device;
-    item->haptic = NULL;
 
     /* Set usage pages. */
     hidProperties = 0;
diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c
index 995001c..281a931 100644
--- a/src/haptic/linux/SDL_syshaptic.c
+++ b/src/haptic/linux/SDL_syshaptic.c
@@ -282,11 +282,11 @@ MaybeAddDevice(const char *path)
         return -1;
     }
 
-    item = (SDL_hapticlist_item *) SDL_malloc(sizeof (SDL_hapticlist_item));
+    item = (SDL_hapticlist_item *) SDL_calloc(1, sizeof (SDL_hapticlist_item));
     if (item == NULL) {
         return -1;
     }
-    SDL_zerop(item);
+
     item->fname = SDL_strdup(path);
     if ( (item->fname == NULL) ) {
         SDL_free(item->fname);
diff --git a/src/haptic/windows/SDL_syshaptic.c b/src/haptic/windows/SDL_syshaptic.c
index 59f7456..8454d93 100644
--- a/src/haptic/windows/SDL_syshaptic.c
+++ b/src/haptic/windows/SDL_syshaptic.c
@@ -253,13 +253,11 @@ DirectInputHaptic_MaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance)
         return -1;  /* not a device we can use. */
     }
 
-    item = (SDL_hapticlist_item *)SDL_malloc( sizeof(SDL_hapticlist_item));
+    item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item));
     if (item == NULL) {
         return SDL_OutOfMemory();
     }
 
-    SDL_zerop(item);
-
     item->name = WIN_StringToUTF8(pdidInstance->tszProductName);
     if (!item->name) {
         SDL_free(item);