From bfd846417d0009da716960800bfc19ad459fdf35 Mon Sep 17 00:00:00 2001 From: Ebrahim Date: Wed, 25 Nov 2026 16:07:01 +0330 Subject: [PATCH 1/3] windows: initialize descriptor lookup tables with memset Replace the per-element initialization loops with explicit memset calls. Compilers already synthesized these calls at higher optimization levels, so this makes the intent explicit without changing behavior. On Windows, int is a 32-bit two's complement type, so filling each byte with 0xFF represents -1. C23 also mandates two's complement (N2218). Assisted-by: deepseek-harness:deepseek-flash --- windows/hidapi_descriptor_reconstruct.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/windows/hidapi_descriptor_reconstruct.c b/windows/hidapi_descriptor_reconstruct.c index 4465c3613..d41d2698b 100644 --- a/windows/hidapi_descriptor_reconstruct.c +++ b/windows/hidapi_descriptor_reconstruct.c @@ -243,10 +243,10 @@ int hid_winapi_descriptor_reconstruct_pp_data(void *preparsed_data, unsigned cha int max_coll_level = 0; int *coll_levels = (int *)malloc(pp_data->NumberLinkCollectionNodes * sizeof(coll_levels[0])); int *coll_number_of_direct_childs = (int *)malloc(pp_data->NumberLinkCollectionNodes * sizeof(coll_number_of_direct_childs[0])); - for (USHORT collection_node_idx = 0; collection_node_idx < pp_data->NumberLinkCollectionNodes; collection_node_idx++) { - coll_levels[collection_node_idx] = -1; - coll_number_of_direct_childs[collection_node_idx] = 0; - } + memset(coll_levels, -1, + pp_data->NumberLinkCollectionNodes * sizeof(coll_levels[0])); + memset(coll_number_of_direct_childs, 0, + pp_data->NumberLinkCollectionNodes * sizeof(coll_number_of_direct_childs[0])); { int actual_coll_level = 0; @@ -382,9 +382,8 @@ int hid_winapi_descriptor_reconstruct_pp_data(void *preparsed_data, unsigned cha struct rd_main_item_node **coll_end_lookup = (struct rd_main_item_node **)malloc(pp_data->NumberLinkCollectionNodes * sizeof(*coll_end_lookup)); { int *coll_last_written_child = (int *)malloc(pp_data->NumberLinkCollectionNodes * sizeof(coll_last_written_child[0])); - for (USHORT collection_node_idx = 0; collection_node_idx < pp_data->NumberLinkCollectionNodes; collection_node_idx++) { - coll_last_written_child[collection_node_idx] = -1; - } + memset(coll_last_written_child, -1, + pp_data->NumberLinkCollectionNodes * sizeof(coll_last_written_child[0])); int actual_coll_level = 0; USHORT collection_node_idx = 0; @@ -528,12 +527,8 @@ int hid_winapi_descriptor_reconstruct_pp_data(void *preparsed_data, unsigned cha { int last_bit_position[NUM_OF_HIDP_REPORT_TYPES][256]; struct rd_main_item_node *last_report_item_lookup[NUM_OF_HIDP_REPORT_TYPES][256]; - for (int rt_idx = 0; rt_idx < NUM_OF_HIDP_REPORT_TYPES; rt_idx++) { - for (int reportid_idx = 0; reportid_idx < 256; reportid_idx++) { - last_bit_position[rt_idx][reportid_idx] = -1; - last_report_item_lookup[rt_idx][reportid_idx] = NULL; - } - } + memset(last_bit_position, -1, sizeof(last_bit_position)); + memset(last_report_item_lookup, 0, sizeof(last_report_item_lookup)); BOOLEAN devicehasReportIDs = FALSE; struct rd_main_item_node *list = main_item_list; // List root; From 8970b9cb05b300ef7eb5be3af1f4ba99c94662af Mon Sep 17 00:00:00 2001 From: Ihor Dutchak Date: Wed, 25 Nov 2026 18:46:36 +0200 Subject: [PATCH 2/3] Update windows/hidapi_descriptor_reconstruct.c --- windows/hidapi_descriptor_reconstruct.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows/hidapi_descriptor_reconstruct.c b/windows/hidapi_descriptor_reconstruct.c index d41d2698b..6943d11da 100644 --- a/windows/hidapi_descriptor_reconstruct.c +++ b/windows/hidapi_descriptor_reconstruct.c @@ -528,7 +528,7 @@ int hid_winapi_descriptor_reconstruct_pp_data(void *preparsed_data, unsigned cha int last_bit_position[NUM_OF_HIDP_REPORT_TYPES][256]; struct rd_main_item_node *last_report_item_lookup[NUM_OF_HIDP_REPORT_TYPES][256]; memset(last_bit_position, -1, sizeof(last_bit_position)); - memset(last_report_item_lookup, 0, sizeof(last_report_item_lookup)); + memset(last_report_item_lookup, NULL, sizeof(last_report_item_lookup)); BOOLEAN devicehasReportIDs = FALSE; struct rd_main_item_node *list = main_item_list; // List root; From 70712110e4ef304e0aa507f63be64e3677205620 Mon Sep 17 00:00:00 2001 From: Ihor Dutchak Date: Wed, 25 Nov 2026 18:51:58 +0200 Subject: [PATCH 3/3] Apply suggestion from @Youw --- windows/hidapi_descriptor_reconstruct.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows/hidapi_descriptor_reconstruct.c b/windows/hidapi_descriptor_reconstruct.c index 6943d11da..f771f62a8 100644 --- a/windows/hidapi_descriptor_reconstruct.c +++ b/windows/hidapi_descriptor_reconstruct.c @@ -528,7 +528,7 @@ int hid_winapi_descriptor_reconstruct_pp_data(void *preparsed_data, unsigned cha int last_bit_position[NUM_OF_HIDP_REPORT_TYPES][256]; struct rd_main_item_node *last_report_item_lookup[NUM_OF_HIDP_REPORT_TYPES][256]; memset(last_bit_position, -1, sizeof(last_bit_position)); - memset(last_report_item_lookup, NULL, sizeof(last_report_item_lookup)); + memset(last_report_item_lookup, 0, sizeof(last_report_item_lookup)); /* fill with NULL pointers */ BOOLEAN devicehasReportIDs = FALSE; struct rd_main_item_node *list = main_item_list; // List root;