mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2025-07-03 00:06:06 +00:00
Fix initialization of mapping structs
This commit is contained in:
parent
469b2ed866
commit
7ff0bcd8fd
@ -22,6 +22,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
struct mapping* mapping_parse(char* mapping) {
|
struct mapping* mapping_parse(char* mapping) {
|
||||||
@ -31,7 +32,7 @@ struct mapping* mapping_parse(char* mapping) {
|
|||||||
if (guid == NULL || name == NULL)
|
if (guid == NULL || name == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
struct mapping* map = malloc(sizeof(struct mapping));
|
struct mapping* map = calloc(sizeof(struct mapping), 1);
|
||||||
if (map == NULL) {
|
if (map == NULL) {
|
||||||
fprintf(stderr, "Not enough memory");
|
fprintf(stderr, "Not enough memory");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@ -39,7 +40,9 @@ struct mapping* mapping_parse(char* mapping) {
|
|||||||
|
|
||||||
strncpy(map->guid, guid, sizeof(map->guid));
|
strncpy(map->guid, guid, sizeof(map->guid));
|
||||||
strncpy(map->name, name, sizeof(map->name));
|
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;
|
char* option;
|
||||||
while ((option = strtok_r(NULL, ",", &strpoint)) != NULL) {
|
while ((option = strtok_r(NULL, ",", &strpoint)) != NULL) {
|
||||||
|
@ -32,6 +32,7 @@ struct mapping {
|
|||||||
bool halfaxis_dpright, halfaxis_dpleft;
|
bool halfaxis_dpright, halfaxis_dpleft;
|
||||||
bool halfaxis_dpup, halfaxis_dpdown;
|
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_leftx, abs_lefty;
|
||||||
short abs_rightx, abs_righty;
|
short abs_rightx, abs_righty;
|
||||||
|
|
||||||
@ -48,6 +49,7 @@ struct mapping {
|
|||||||
short abs_lefttrigger, abs_righttrigger;
|
short abs_lefttrigger, abs_righttrigger;
|
||||||
short btn_lefttrigger, btn_righttrigger;
|
short btn_lefttrigger, btn_righttrigger;
|
||||||
|
|
||||||
|
/* next must be the last member after the list of mapping indices! */
|
||||||
struct mapping* next;
|
struct mapping* next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user