diff --git a/src/input/mapping.c b/src/input/mapping.c index 86d0425..0096867 100644 --- a/src/input/mapping.c +++ b/src/input/mapping.c @@ -22,6 +22,7 @@ #include #include #include +#include #include struct mapping* mapping_parse(char* mapping) { @@ -31,7 +32,7 @@ struct mapping* mapping_parse(char* mapping) { if (guid == NULL || name == NULL) return NULL; - struct mapping* map = malloc(sizeof(struct mapping)); + struct mapping* map = calloc(sizeof(struct mapping), 1); if (map == NULL) { fprintf(stderr, "Not enough memory"); exit(EXIT_FAILURE); @@ -39,7 +40,9 @@ struct mapping* mapping_parse(char* mapping) { strncpy(map->guid, guid, sizeof(map->guid)); strncpy(map->name, name, sizeof(map->name)); - memset(&map->abs_leftx, -1, sizeof(short) * 31); + + /* Initialize all mapping indices to -1 to ensure they won't match anything */ + memset(&map->abs_leftx, -1, offsetof(struct mapping, next) - offsetof(struct mapping, abs_leftx)); char* option; while ((option = strtok_r(NULL, ",", &strpoint)) != NULL) { diff --git a/src/input/mapping.h b/src/input/mapping.h index 19c6798..9668fda 100644 --- a/src/input/mapping.h +++ b/src/input/mapping.h @@ -32,6 +32,7 @@ struct mapping { bool halfaxis_dpright, halfaxis_dpleft; bool halfaxis_dpup, halfaxis_dpdown; + /* abs_leftx must be the first member of the list of mapping indices! */ short abs_leftx, abs_lefty; short abs_rightx, abs_righty; @@ -48,6 +49,7 @@ struct mapping { short abs_lefttrigger, abs_righttrigger; short btn_lefttrigger, btn_righttrigger; + /* next must be the last member after the list of mapping indices! */ struct mapping* next; };