Skip to content

Commit 5a00eae

Browse files
tkanteckmdcornu
authored andcommitted
igzip: several fixes for issues reported by static code analysis
Signed-off-by: Tomasz Kantecki <[email protected]>
1 parent c83771e commit 5a00eae

8 files changed

+114
-86
lines changed

igzip/checksum32_funcs_test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ int update_over_mod_test(func_case_t * test_func)
303303
unsigned char *buf = NULL;
304304

305305
buf = malloc(ADLER_MOD);
306+
if (buf == NULL)
307+
return 1;
306308
memset(buf, 0xff, ADLER_MOD);
307309

308310
c_ref = c_dut = rand();

igzip/generate_custom_hufftables.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,10 @@ int main(int argc, char *argv[])
361361

362362
if (argc > 3 && argv[1][0] == '-' && argv[1][1] == 'd') {
363363
dict_file = fopen(argv[2], "r");
364+
if (dict_file == NULL) {
365+
printf("File \"%s\" open error!\n", argv[2]);
366+
return 1;
367+
}
364368

365369
fseek(dict_file, 0, SEEK_END);
366370
dict_file_length = ftell(dict_file);
@@ -388,6 +392,10 @@ int main(int argc, char *argv[])
388392

389393
if ((argc > argi + 1) && argv[argi][0] == '-' && argv[argi][1] == 'h') {
390394
hist_file = fopen(argv[argi + 1], "r+");
395+
if (hist_file == NULL) {
396+
printf("File \"%s\" open error!\n", argv[argi + 1]);
397+
return 1;
398+
}
391399
fseek(hist_file, 0, SEEK_END);
392400
hist_file_length = ftell(hist_file);
393401
fseek(hist_file, 0, SEEK_SET);

igzip/igzip_build_hash_table_perf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <getopt.h>
66
#include "igzip_lib.h"
77
#include "test.h"
8+
#include "huff_codes.h"
89

910
#define DICT_LEN 32*1024
1011

@@ -26,6 +27,7 @@ int main(int argc, char *argv[])
2627
uint32_t dict_len = DICT_LEN;
2728

2829
stream.level = 0;
30+
stream.internal_state.hash_mask = LVL0_HASH_MASK;
2931
create_rand_data(dict, dict_len);
3032

3133
struct perf start;

igzip/igzip_inflate_test.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,8 @@ int inflate_multi_pass(uint8_t * compress_buf, uint64_t compress_len,
7474
comp_tmp_size = compress_len - comp_processed;
7575

7676
if (comp_tmp_size != 0) {
77-
if (comp_tmp != NULL) {
77+
if (comp_tmp != NULL)
7878
free(comp_tmp);
79-
comp_tmp = NULL;
80-
}
8179

8280
comp_tmp = malloc(comp_tmp_size);
8381

@@ -113,7 +111,6 @@ int inflate_multi_pass(uint8_t * compress_buf, uint64_t compress_len,
113111
if (uncomp_tmp != NULL) {
114112
fflush(0);
115113
free(uncomp_tmp);
116-
uncomp_tmp = NULL;
117114
}
118115

119116
uncomp_tmp = malloc(uncomp_tmp_size);
@@ -275,7 +272,9 @@ int main(int argc, char **argv)
275272
exit(0);
276273
}
277274

278-
uncompressed_length = fread(uncompressed_stream, 1, file_length, file);
275+
uncompressed_length =
276+
(uncompressed_stream == NULL) ? 0 : fread(uncompressed_stream, 1,
277+
file_length, file);
279278
uncompressed_test_stream_length = uncompressed_length;
280279
ret =
281280
test(compressed_stream, &compressed_length, uncompressed_stream,

igzip/igzip_perf.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,13 +475,19 @@ int isal_deflate_dict_perf(uint8_t * outbuf, uint64_t * outbuf_size, uint8_t * i
475475
}
476476

477477
stream.level = level;
478-
isal_deflate_process_dict(&stream, &dict_str, dict_buf, dict_file_size);
478+
if (isal_deflate_process_dict(&stream, &dict_str, dict_buf, dict_file_size) != COMP_OK) {
479+
if (level_buf != NULL)
480+
free(level_buf);
481+
return 1;
482+
}
479483

480484
BENCHMARK(start, time, check =
481485
isal_deflate_dict_round(&stream, outbuf, *outbuf_size, inbuf,
482486
inbuf_size, level, level_buf,
483487
level_size_buf[level], flush_type, hist_bits,
484488
&dict_str));
489+
if (level_buf != NULL)
490+
free(level_buf);
485491
*outbuf_size = stream.total_out;
486492
return check;
487493
}
@@ -879,8 +885,13 @@ int main(int argc, char *argv[])
879885
printf("\n");
880886

881887
if (outfile != NULL && i + 1 == compression_queue_size) {
882-
FILE *out;
883-
out = fopen(outfile, "wb");
888+
FILE *out = fopen(outfile, "wb");
889+
890+
if (out == NULL) {
891+
fprintf(stderr, "Could not write to the output file \"%s\"\n",
892+
outfile);
893+
exit(0);
894+
}
884895
fwrite(compressbuf, 1, info.deflate_size, out);
885896
fclose(out);
886897
}

0 commit comments

Comments
 (0)