mirror of https://github.com/nirenjan/libx52.git
fix: Handle issues found by SonarQube
parent
75e6f253c9
commit
283b476c5e
|
|
@ -31,7 +31,7 @@ static volatile libx52io_report new_report;
|
|||
|
||||
static int report_button_change(vkm_mouse_button button, int index)
|
||||
{
|
||||
vkm_result rc;
|
||||
vkm_result rc = VKM_ERROR_NO_CHANGE;
|
||||
bool old_button = old_report.button[index];
|
||||
bool new_button = new_report.button[index];
|
||||
vkm_button_state state;
|
||||
|
|
@ -50,7 +50,7 @@ static int report_button_change(vkm_mouse_button button, int index)
|
|||
|
||||
static int report_wheel(void)
|
||||
{
|
||||
vkm_result rc;
|
||||
vkm_result rc = VKM_ERROR_NO_CHANGE;
|
||||
int wheel = 0;
|
||||
bool scroll_up = new_report.button[LIBX52IO_BTN_MOUSE_SCROLL_UP];
|
||||
bool scroll_dn = new_report.button[LIBX52IO_BTN_MOUSE_SCROLL_DN];
|
||||
|
|
|
|||
|
|
@ -231,6 +231,8 @@ int libx52_init(libx52_device **dev)
|
|||
|
||||
void libx52_exit(libx52_device *dev)
|
||||
{
|
||||
volatile unsigned char *vp;
|
||||
|
||||
if (!dev) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -239,7 +241,10 @@ void libx52_exit(libx52_device *dev)
|
|||
libusb_exit(dev->ctx);
|
||||
|
||||
/* Clear the memory to prevent reuse */
|
||||
memset(dev, 0, sizeof(*dev));
|
||||
vp = (volatile unsigned char *)dev;
|
||||
for (int i = 0; i < sizeof(*dev); i++) {
|
||||
vp[i] = (unsigned char)0;
|
||||
}
|
||||
|
||||
free(dev);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -218,9 +218,7 @@ error:
|
|||
|
||||
void vkm_exit(vkm_context *ctx)
|
||||
{
|
||||
char *name;
|
||||
struct libevdev_uinput *uidev;
|
||||
struct libevdev *dev;
|
||||
volatile unsigned char *vp;
|
||||
|
||||
if (ctx == NULL) {
|
||||
return;
|
||||
|
|
@ -228,20 +226,20 @@ void vkm_exit(vkm_context *ctx)
|
|||
|
||||
(void)vkm_reset(ctx);
|
||||
|
||||
dev = ctx->dev;
|
||||
uidev = ctx->uidev;
|
||||
name = ctx->name;
|
||||
free(ctx->name);
|
||||
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
|
||||
free(name);
|
||||
|
||||
if (uidev) {
|
||||
libevdev_uinput_destroy(uidev);
|
||||
if (ctx->uidev) {
|
||||
libevdev_uinput_destroy(ctx->uidev);
|
||||
}
|
||||
|
||||
if (dev) {
|
||||
libevdev_free(dev);
|
||||
if (ctx->dev) {
|
||||
libevdev_free(ctx->dev);
|
||||
}
|
||||
|
||||
/* Clear the memory to prevent reuse */
|
||||
vp = (volatile unsigned char *)ctx;
|
||||
for (int i = 0; i < sizeof(*ctx); i++) {
|
||||
vp[i] = (unsigned char)0;
|
||||
}
|
||||
|
||||
free(ctx);
|
||||
|
|
|
|||
Loading…
Reference in New Issue