Skip to content

Commit f5c821e

Browse files
Fix Coverity issues CID1530052, CID1530054, CID1530055 (#552)
1 parent f0211fb commit f5c821e

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

windows/hidapi_descriptor_reconstruct.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ int hid_winapi_descriptor_reconstruct_pp_data(void *preparsed_data, unsigned cha
205205
rd_bit_range ****coll_bit_range;
206206
coll_bit_range = malloc(pp_data->NumberLinkCollectionNodes * sizeof(*coll_bit_range));
207207
for (USHORT collection_node_idx = 0; collection_node_idx < pp_data->NumberLinkCollectionNodes; collection_node_idx++) {
208-
coll_bit_range[collection_node_idx] = malloc(256 * sizeof(coll_bit_range[0])); // 256 possible report IDs (incl. 0x00)
208+
coll_bit_range[collection_node_idx] = malloc(256 * sizeof(*coll_bit_range[0])); // 256 possible report IDs (incl. 0x00)
209209
for (int reportid_idx = 0; reportid_idx < 256; reportid_idx++) {
210-
coll_bit_range[collection_node_idx][reportid_idx] = malloc(NUM_OF_HIDP_REPORT_TYPES * sizeof(coll_bit_range[0][0]));
210+
coll_bit_range[collection_node_idx][reportid_idx] = malloc(NUM_OF_HIDP_REPORT_TYPES * sizeof(*coll_bit_range[0][0]));
211211
for (HIDP_REPORT_TYPE rt_idx = 0; rt_idx < NUM_OF_HIDP_REPORT_TYPES; rt_idx++) {
212212
coll_bit_range[collection_node_idx][reportid_idx][rt_idx] = malloc(sizeof(rd_bit_range));
213213
coll_bit_range[collection_node_idx][reportid_idx][rt_idx]->FirstBit = -1;
@@ -378,8 +378,7 @@ int hid_winapi_descriptor_reconstruct_pp_data(void *preparsed_data, unsigned cha
378378
// ***************************************************************************************
379379
// Create sorted main_item_list containing all the Collection and CollectionEnd main items
380380
// ***************************************************************************************
381-
struct rd_main_item_node *main_item_list = (struct rd_main_item_node*)malloc(sizeof(main_item_list));
382-
main_item_list = NULL; // List root
381+
struct rd_main_item_node *main_item_list = NULL; // List root
383382
// Lookup table to find the Collection items in the list by index
384383
struct rd_main_item_node **coll_begin_lookup = malloc(pp_data->NumberLinkCollectionNodes * sizeof(*coll_begin_lookup));
385384
struct rd_main_item_node **coll_end_lookup = malloc(pp_data->NumberLinkCollectionNodes * sizeof(*coll_end_lookup));

windows/test/hid_report_reconstructor_test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ static hidp_preparsed_data * alloc_preparsed_data_from_file(char* filename)
5555
}
5656
if (!header_read_success) {
5757
fprintf(stderr, "ERROR: Couldn't read PP Data header (missing newline)\n");
58+
fclose(file);
5859
return NULL;
5960
}
6061
printf("'Virtual' Device Read: %04hx %04hx\n", vendor_id, product_id);

0 commit comments

Comments
 (0)