mirror of
https://github.com/libretro/RetroArch
synced 2025-03-30 07:20:36 +00:00
Clean up dumb compile warnings, fix crash bug
== DETAILS - the free() method of the hid_driver_t interface needs its parameter defined as const in order for the compiler to stop complaining about losing const-ness. - if a joypad list is created with <MAX_USERS slots in it, the destroy() function will crash because it assumes there are MAX_USERS entries. To do this, the allocate function creates n+1 slots, and gives the last slot a canary value that the destroy() method can then watch for when iterating through the list.
This commit is contained in:
parent
52c754cfa8
commit
0ae7ffe0d3
@ -42,11 +42,28 @@ int pad_connection_find_vacant_pad(joypad_connection_t *joyconn)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void set_end_of_list(joypad_connection_t *list, unsigned end)
|
||||
{
|
||||
joypad_connection_t *entry = (joypad_connection_t *)&list[end];
|
||||
entry->connected = false;
|
||||
entry->iface = NULL;
|
||||
entry->data = (void *)0xdeadbeef;
|
||||
}
|
||||
|
||||
static bool joypad_is_end_of_list(joypad_connection_t *pad) {
|
||||
return pad && !pad->connected && !pad->iface && pad->data == (void *)0xdeadbeef;
|
||||
}
|
||||
|
||||
/**
|
||||
* Since the pad_connection_destroy() call needs to iterate through this
|
||||
* list, we allocate pads+1 entries and use the extra spot to store a
|
||||
* marker.
|
||||
*/
|
||||
joypad_connection_t *pad_connection_init(unsigned pads)
|
||||
{
|
||||
unsigned i;
|
||||
joypad_connection_t *joyconn = (joypad_connection_t*)
|
||||
calloc(pads, sizeof(joypad_connection_t));
|
||||
calloc(pads+1, sizeof(joypad_connection_t));
|
||||
|
||||
if (!joyconn)
|
||||
return NULL;
|
||||
@ -60,6 +77,8 @@ joypad_connection_t *pad_connection_init(unsigned pads)
|
||||
conn->data = NULL;
|
||||
}
|
||||
|
||||
set_end_of_list(joyconn, pads);
|
||||
|
||||
return joyconn;
|
||||
}
|
||||
|
||||
@ -208,7 +227,12 @@ void pad_connection_destroy(joypad_connection_t *joyconn)
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < MAX_USERS; i ++)
|
||||
pad_connection_pad_deinit(&joyconn[i], i);
|
||||
{
|
||||
if(joypad_is_end_of_list(&joyconn[i]))
|
||||
break;
|
||||
|
||||
pad_connection_pad_deinit(&joyconn[i], i);
|
||||
}
|
||||
|
||||
free(joyconn);
|
||||
}
|
||||
|
@ -44,7 +44,6 @@ typedef struct wiiu_input
|
||||
{
|
||||
bool blocked;
|
||||
const input_device_driver_t *joypad;
|
||||
const hid_driver_t *hid_joypad;
|
||||
} wiiu_input_t;
|
||||
|
||||
void kb_connection_callback(KBDKeyEvent *key)
|
||||
@ -126,8 +125,6 @@ static void wiiu_input_poll(void *data)
|
||||
|
||||
if(wiiu->joypad)
|
||||
wiiu->joypad->poll();
|
||||
if(wiiu->hid_joypad)
|
||||
wiiu->hid_joypad->poll(hid_driver_get_data());
|
||||
}
|
||||
|
||||
static bool wiiu_key_pressed(int key)
|
||||
@ -181,12 +178,6 @@ static void wiiu_input_free_input(void *data)
|
||||
if (wiiu && wiiu->joypad)
|
||||
wiiu->joypad->destroy();
|
||||
|
||||
if (wiiu && wiiu->hid_joypad)
|
||||
{
|
||||
wiiu->hid_joypad->free(hid_driver_get_data());
|
||||
hid_driver_reset_data();
|
||||
}
|
||||
|
||||
KBDTeardown();
|
||||
|
||||
free(data);
|
||||
@ -200,7 +191,6 @@ static void* wiiu_input_init(const char *joypad_driver)
|
||||
|
||||
DEBUG_STR(joypad_driver);
|
||||
wiiu->joypad = input_joypad_init_driver(joypad_driver, wiiu);
|
||||
wiiu->hid_joypad = input_hid_init_first();
|
||||
|
||||
KBDSetup(&kb_connection_callback,
|
||||
&kb_disconnection_callback,&kb_key_callback);
|
||||
|
@ -1424,7 +1424,7 @@ static int16_t btstack_hid_joypad_axis(void *data, unsigned port, uint32_t joyax
|
||||
return val;
|
||||
}
|
||||
|
||||
static void btstack_hid_free(void *data)
|
||||
static void btstack_hid_free(const void *data)
|
||||
{
|
||||
btstack_hid_t *hid = (btstack_hid_t*)data;
|
||||
|
||||
|
@ -830,7 +830,7 @@ error:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void iohidmanager_hid_free(void *data)
|
||||
static void iohidmanager_hid_free(const void *data)
|
||||
{
|
||||
iohidmanager_hid_t *hid_apple = (iohidmanager_hid_t*)data;
|
||||
|
||||
|
@ -509,7 +509,7 @@ static int16_t libusb_hid_joypad_axis(void *data,
|
||||
return val;
|
||||
}
|
||||
|
||||
static void libusb_hid_free(void *data)
|
||||
static void libusb_hid_free(const void *data)
|
||||
{
|
||||
libusb_hid_t *hid = (libusb_hid_t*)data;
|
||||
|
||||
|
@ -80,7 +80,7 @@ static void *null_hid_init(void)
|
||||
return (null_hid_t*)calloc(1, sizeof(null_hid_t));
|
||||
}
|
||||
|
||||
static void null_hid_free(void *data)
|
||||
static void null_hid_free(const void *data)
|
||||
{
|
||||
null_hid_t *hid_null = (null_hid_t*)data;
|
||||
|
||||
|
@ -111,7 +111,7 @@ static void *wiiu_hid_init(void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void wiiu_hid_free(void *data)
|
||||
static void wiiu_hid_free(const void *data)
|
||||
{
|
||||
wiiu_hid_t *hid = (wiiu_hid_t*)data;
|
||||
|
||||
|
@ -546,7 +546,7 @@ static int16_t wiiusb_hid_joypad_axis(void *data,
|
||||
return val;
|
||||
}
|
||||
|
||||
static void wiiusb_hid_free(void *data)
|
||||
static void wiiusb_hid_free(const void *data)
|
||||
{
|
||||
struct wiiusb_adapter *adapter = NULL;
|
||||
struct wiiusb_adapter *next_adapter = NULL;
|
||||
|
@ -185,7 +185,7 @@ struct hid_driver
|
||||
{
|
||||
void *(*init)(void);
|
||||
bool (*query_pad)(void *, unsigned);
|
||||
void (*free)(void *);
|
||||
void (*free)(const void *);
|
||||
bool (*button)(void *, unsigned, uint16_t);
|
||||
void (*get_buttons)(void *, unsigned, retro_bits_t *);
|
||||
int16_t (*axis)(void *, unsigned, uint32_t);
|
||||
|
@ -69,6 +69,18 @@
|
||||
// wiimote not attached on this channel
|
||||
#define WIIMOTE_TYPE_NONE 0xFD
|
||||
|
||||
/**
|
||||
* These are used to map pad names to controller mappings. You can
|
||||
* change these relatively free-form.
|
||||
*/
|
||||
|
||||
#define PAD_NAME_WIIU_GAMEPAD "WiiU Gamepad"
|
||||
#define PAD_NAME_WIIU_PRO "WiiU Pro Controller"
|
||||
#define PAD_NAME_WIIMOTE "Wiimote Controller"
|
||||
#define PAD_NAME_NUNCHUK "Wiimote+Nunchuk Controller"
|
||||
#define PAD_NAME_CLASSIC "Classic Controller"
|
||||
#define PAD_NAME_HID "HID Controller"
|
||||
|
||||
/**
|
||||
* The Wii U gamepad and wiimotes have 3 sets of x/y axes. The third
|
||||
* is used by the gamepad for the touchpad driver; the wiimotes is
|
||||
@ -95,6 +107,7 @@ struct _wiiu_pad_functions {
|
||||
};
|
||||
|
||||
extern wiiu_pad_functions_t pad_functions;
|
||||
extern input_device_driver_t wiiu_joypad;
|
||||
extern input_device_driver_t wpad_driver;
|
||||
extern input_device_driver_t kpad_driver;
|
||||
extern input_device_driver_t hidpad_driver;
|
||||
|
Loading…
x
Reference in New Issue
Block a user