فهرست منبع

Zero out haptic linked list items on creation

(thanks to Turo Lamminen for the report!)
Gabriel Jacobo 11 سال پیش
والد
کامیت
1084421cca
3فایلهای تغییر یافته به همراه4 افزوده شده و 7 حذف شده
  1. 1 2
      src/haptic/darwin/SDL_syshaptic.c
  2. 2 2
      src/haptic/linux/SDL_syshaptic.c
  3. 1 3
      src/haptic/windows/SDL_syshaptic.c

+ 1 - 2
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) {
     if (item == NULL) {
         return SDL_SetError("Could not allocate haptic storage");
         return SDL_SetError("Could not allocate haptic storage");
     }
     }
@@ -248,7 +248,6 @@ MacHaptic_MaybeAddDevice( io_object_t device )
     /* Set basic device data. */
     /* Set basic device data. */
     HIDGetDeviceProduct(device, item->name);
     HIDGetDeviceProduct(device, item->name);
     item->dev = device;
     item->dev = device;
-    item->haptic = NULL;
 
 
     /* Set usage pages. */
     /* Set usage pages. */
     hidProperties = 0;
     hidProperties = 0;

+ 2 - 2
src/haptic/linux/SDL_syshaptic.c

@@ -282,11 +282,11 @@ MaybeAddDevice(const char *path)
         return -1;
         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) {
     if (item == NULL) {
         return -1;
         return -1;
     }
     }
-    SDL_zerop(item);
+
     item->fname = SDL_strdup(path);
     item->fname = SDL_strdup(path);
     if ( (item->fname == NULL) ) {
     if ( (item->fname == NULL) ) {
         SDL_free(item->fname);
         SDL_free(item->fname);

+ 1 - 3
src/haptic/windows/SDL_syshaptic.c

@@ -253,13 +253,11 @@ DirectInputHaptic_MaybeAddDevice(const DIDEVICEINSTANCE * pdidInstance)
         return -1;  /* not a device we can use. */
         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) {
     if (item == NULL) {
         return SDL_OutOfMemory();
         return SDL_OutOfMemory();
     }
     }
 
 
-    SDL_zerop(item);
-
     item->name = WIN_StringToUTF8(pdidInstance->tszProductName);
     item->name = WIN_StringToUTF8(pdidInstance->tszProductName);
     if (!item->name) {
     if (!item->name) {
         SDL_free(item);
         SDL_free(item);