From faa6ece881d3ae28c016567e1cc46fe5a894cfdc Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 3 May 2018 19:45:59 +0200 Subject: [PATCH] chg: converting some more malloc calls -> calloc --- client/cmdanalyse.c | 4 ++-- client/fpga_compress.c | 2 +- client/hid-flasher/flash.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/client/cmdanalyse.c b/client/cmdanalyse.c index a0e6c7ab3..81049841a 100644 --- a/client/cmdanalyse.c +++ b/client/cmdanalyse.c @@ -253,8 +253,8 @@ int CmdAnalyseCRC(const char *Cmd) { if ( len & 1 ) return usage_analyse_crc(); // add 1 for null terminator. - uint8_t *data = malloc(len+1); - if ( data == NULL ) return 1; + uint8_t *data = calloc(len+1, sizeof(uint8_t)); + if ( !data ) return 1; if ( param_gethex(Cmd, 0, data, len)) { free(data); diff --git a/client/fpga_compress.c b/client/fpga_compress.c index b2a3a8d67..d7caff69a 100644 --- a/client/fpga_compress.c +++ b/client/fpga_compress.c @@ -134,7 +134,7 @@ int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile, bool hardn // estimate the size of the compressed output uint32_t outsize_max = deflateBound(&compressed_fpga_stream, compressed_fpga_stream.avail_in); - uint8_t *outbuf = malloc(outsize_max); + uint8_t *outbuf = calloc(outsize_max, sizeof(uint8_t)); compressed_fpga_stream.next_out = outbuf; compressed_fpga_stream.avail_out = outsize_max; diff --git a/client/hid-flasher/flash.c b/client/hid-flasher/flash.c index 8fd59427d..c7ce3c8a3 100644 --- a/client/hid-flasher/flash.c +++ b/client/hid-flasher/flash.c @@ -113,7 +113,7 @@ static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs, uint32_t new_length = this_end - prev_seg->start; uint32_t this_offset = paddr - prev_seg->start; uint32_t hole = this_offset - prev_seg->length; - uint8_t *new_data = malloc(new_length); + uint8_t *new_data = calloc(new_length, sizeof(uint8_t)); if (!new_data) { fprintf(stderr, "Out of memory\n"); free(data);