Skip to content

Commit a2a93c2

Browse files
Sameer VazeAkhil Goyal
authored andcommitted
app/compress-perf: fix dictionary argument handling
Removes possible assignment of a signed value to an unsigned parameter. Also makes dictionary an optional argument. Coverity issue: 490944 Fixes: 5688155 ("app/compress-perf: support dictionaries and PDCP checksum") Signed-off-by: Sameer Vaze <[email protected]>
1 parent e1627f2 commit a2a93c2

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

app/test-compress-perf/comp_perf_options_parse.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ static struct option lgopts[] = {
660660
{ CPERF_LEVEL, required_argument, 0, 0 },
661661
{ CPERF_WINDOW_SIZE, required_argument, 0, 0 },
662662
{ CPERF_EXTERNAL_MBUFS, 0, 0, 0 },
663-
{ CPERF_DICTIONARY, required_argument, 0, 0 },
663+
{ CPERF_DICTIONARY, optional_argument, 0, 0 },
664664
{ CPERF_CYCLECOUNT_DELAY_US, required_argument, 0, 0 },
665665
{ NULL, 0, 0, 0 }
666666
};

app/test-compress-perf/main.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,16 +355,22 @@ comp_perf_dump_dictionary_data(struct comp_test_data *test_data)
355355
RTE_LOG(ERR, USER1, "Size of input could not be calculated\n");
356356
goto end;
357357
}
358-
size_t actual_file_sz = ftell(f);
358+
long file_sz = ftell(f);
359359
/* If extended input data size has not been set,
360360
* input data size = file size
361361
*/
362362

363+
if (file_sz < 0) {
364+
RTE_LOG(ERR, USER1, "Actual file size could not be determined\n");
365+
goto end;
366+
}
367+
368+
size_t actual_file_sz = (size_t)file_sz;
369+
363370
if (test_data->dictionary_data_sz == 0)
364371
test_data->dictionary_data_sz = actual_file_sz;
365372

366-
if (test_data->dictionary_data_sz <= 0 || actual_file_sz <= 0 ||
367-
fseek(f, 0, SEEK_SET) != 0) {
373+
if (fseek(f, 0, SEEK_SET) != 0) {
368374
RTE_LOG(ERR, USER1, "Size of input could not be calculated\n");
369375
goto end;
370376
}
@@ -386,11 +392,15 @@ comp_perf_dump_dictionary_data(struct comp_test_data *test_data)
386392

387393
if (fread(data, data_to_read, 1, f) != 1) {
388394
RTE_LOG(ERR, USER1, "Input file could not be read\n");
395+
if (test_data->dictionary_data)
396+
rte_free(test_data->dictionary_data);
389397
goto end;
390398
}
391399
if (fseek(f, 0, SEEK_SET) != 0) {
392400
RTE_LOG(ERR, USER1,
393401
"Size of input could not be calculated\n");
402+
if (test_data->dictionary_data)
403+
rte_free(test_data->dictionary_data);
394404
goto end;
395405
}
396406
remaining_data -= data_to_read;
@@ -414,9 +424,6 @@ comp_perf_dump_dictionary_data(struct comp_test_data *test_data)
414424
if (f)
415425
fclose(f);
416426

417-
if (test_data->dictionary_data)
418-
rte_free(test_data->dictionary_data);
419-
420427
return ret;
421428
}
422429

0 commit comments

Comments
 (0)