Skip to content

Commit 4039006

Browse files
committed
Gamepad / Keyboard / Mouse: improves device error handling and memory cleanup
1 parent 0bb5b4c commit 4039006

File tree

3 files changed

+40
-27
lines changed

3 files changed

+40
-27
lines changed

src/modules/gamepad/gamepad.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,26 +87,29 @@ bool ffPrintGamepad(FFGamepadOptions* options)
8787
}
8888
}
8989

90+
bool ret = true;
9091
if(!filtered.length)
9192
{
9293
ffPrintError(FF_GAMEPAD_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "All devices are ignored");
93-
return false;
94+
ret = false;
9495
}
95-
96-
uint8_t index = 0;
97-
FF_LIST_FOR_EACH(FFGamepadDevice*, pdevice, filtered)
96+
else
9897
{
99-
FFGamepadDevice* device = *pdevice;
100-
printDevice(options, device, filtered.length > 1 ? ++index : 0);
101-
}
98+
uint8_t index = 0;
99+
FF_LIST_FOR_EACH(FFGamepadDevice*, pdevice, filtered)
100+
{
101+
FFGamepadDevice* device = *pdevice;
102+
printDevice(options, device, filtered.length > 1 ? ++index : 0);
103+
}
102104

103-
FF_LIST_FOR_EACH(FFGamepadDevice, device, result)
104-
{
105-
ffStrbufDestroy(&device->serial);
106-
ffStrbufDestroy(&device->name);
105+
FF_LIST_FOR_EACH(FFGamepadDevice, device, result)
106+
{
107+
ffStrbufDestroy(&device->serial);
108+
ffStrbufDestroy(&device->name);
109+
}
107110
}
108111

109-
return true;
112+
return ret;
110113
}
111114

112115
void ffParseGamepadJsonObject(FFGamepadOptions* options, yyjson_val* module)

src/modules/keyboard/keyboard.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,25 @@ bool ffPrintKeyboard(FFKeyboardOptions* options)
5858
}
5959
}
6060

61+
bool ret = true;
6162
if(!filtered.length)
6263
{
6364
ffPrintError(FF_KEYBOARD_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "All devices are ignored");
64-
return false;
65+
ret = false;
6566
}
66-
67-
uint8_t index = 0;
68-
FF_LIST_FOR_EACH(FFKeyboardDevice*, pdevice, filtered)
67+
else
6968
{
70-
FFKeyboardDevice* device = *pdevice;
71-
printDevice(options, device, filtered.length > 1 ? ++index : 0);
72-
ffStrbufDestroy(&device->serial);
73-
ffStrbufDestroy(&device->name);
69+
uint8_t index = 0;
70+
FF_LIST_FOR_EACH(FFKeyboardDevice*, pdevice, filtered)
71+
{
72+
FFKeyboardDevice* device = *pdevice;
73+
printDevice(options, device, filtered.length > 1 ? ++index : 0);
74+
ffStrbufDestroy(&device->serial);
75+
ffStrbufDestroy(&device->name);
76+
}
7477
}
7578

76-
return true;
79+
return ret;
7780
}
7881

7982
void ffParseKeyboardJsonObject(FFKeyboardOptions* options, yyjson_val* module)

src/modules/mouse/mouse.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,29 @@ bool ffPrintMouse(FFMouseOptions* options)
5858
}
5959
}
6060

61+
bool ret = true;
6162
if(!filtered.length)
6263
{
6364
ffPrintError(FF_MOUSE_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "All devices are ignored");
64-
return false;
65+
ret = false;
66+
}
67+
else
68+
{
69+
uint8_t index = 0;
70+
FF_LIST_FOR_EACH(FFMouseDevice*, pdevice, filtered)
71+
{
72+
FFMouseDevice* device = *pdevice;
73+
printDevice(options, device, filtered.length > 1 ? ++index : 0);
74+
}
6575
}
6676

67-
uint8_t index = 0;
68-
FF_LIST_FOR_EACH(FFMouseDevice*, pdevice, filtered)
77+
FF_LIST_FOR_EACH(FFMouseDevice, device, result)
6978
{
70-
FFMouseDevice* device = *pdevice;
71-
printDevice(options, device, filtered.length > 1 ? ++index : 0);
7279
ffStrbufDestroy(&device->serial);
7380
ffStrbufDestroy(&device->name);
7481
}
7582

76-
return true;
83+
return ret;
7784
}
7885

7986
void ffParseMouseJsonObject(FFMouseOptions* options, yyjson_val* module)

0 commit comments

Comments
 (0)