chg: use calloc

This commit is contained in:
iceman1001 2019-01-30 21:40:50 +01:00
parent 99b6087b01
commit ad72a424ef
15 changed files with 36 additions and 27 deletions

View file

@ -209,7 +209,7 @@ static int compare_count_bitflip_bitarrays(const void *b1, const void *b2)
static voidpf inflate_malloc(voidpf opaque, uInt items, uInt size)
{
return malloc(items*size);
return calloc(items*size, sizeof(uint8_t));
}

View file

@ -59,7 +59,7 @@ static void usage(void)
static voidpf fpga_deflate_malloc(voidpf opaque, uInt items, uInt size)
{
return malloc(items*size);
return calloc(items*size, sizeof(uint8_t));
}
@ -89,9 +89,9 @@ int zlib_compress(FILE *infile[], uint8_t num_infiles, FILE *outfile, bool hardn
z_stream compressed_fpga_stream;
if (hardnested_mode) {
fpga_config = malloc(num_infiles * HARDNESTED_TABLE_SIZE);
fpga_config = calloc(num_infiles * HARDNESTED_TABLE_SIZE, sizeof(uint8_t));
} else {
fpga_config = malloc(num_infiles * FPGA_CONFIG_SIZE);
fpga_config = calloc(num_infiles * FPGA_CONFIG_SIZE, sizeof(uint8_t));
}
// read the input files. Interleave them into fpga_config[]
i = 0;

View file

@ -40,7 +40,7 @@ static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs,
flash_seg_t *seg;
uint32_t last_end = 0;
ctx->segments = malloc(sizeof(flash_seg_t) * num_phdrs);
ctx->segments = calloc(sizeof(flash_seg_t) * num_phdrs, sizeof(uint8_t));
if (!ctx->segments) {
fprintf(stderr, "Out of memory\n");
return -1;
@ -90,7 +90,7 @@ static int build_segs_from_phdrs(flash_file_t *ctx, FILE *fd, Elf32_Phdr *phdrs,
uint8_t *data;
// make extra space if we need to move the data forward
data = malloc(filesz + BLOCK_SIZE);
data = calloc(filesz + BLOCK_SIZE, sizeof(uint8_t));
if (!data) {
fprintf(stderr, "Out of memory\n");
return -1;
@ -226,7 +226,7 @@ int flash_load(flash_file_t *ctx, const char *name, int can_write_bl)
}
num_phdrs = le16(ehdr.e_phnum);
phdrs = malloc(le16(ehdr.e_phnum) * sizeof(Elf32_Phdr));
phdrs = calloc(le16(ehdr.e_phnum) * sizeof(Elf32_Phdr), sizeof(uint8_t));
if (!phdrs) {
fprintf(stderr, "Out of memory\n");
goto fail;

View file

@ -224,7 +224,7 @@ void doMAC(uint8_t *cc_nr_p, uint8_t *div_key_p, uint8_t mac[4])
{
uint8_t cc_nr[13] = { 0 };
uint8_t div_key[8];
//cc_nr=(uint8_t*)malloc(length+1);
//cc_nr=(uint8_t*) calloc(length+1, sizeof(uint8_t));
memcpy(cc_nr, cc_nr_p, 12);
memcpy(div_key, div_key_p, 8);
@ -244,7 +244,7 @@ void doMAC_N(uint8_t *address_data_p, uint8_t address_data_size, uint8_t *div_ke
{
uint8_t *address_data;
uint8_t div_key[8];
address_data = (uint8_t*) malloc(address_data_size);
address_data = (uint8_t*) calloc(address_data_size, sizeof(uint8_t));
memcpy(address_data, address_data_p, address_data_size);
memcpy(div_key, div_key_p, 8);

View file

@ -493,7 +493,7 @@ int bruteforceDump(uint8_t dump[], size_t dumpsize, uint16_t keytable[]) {
uint64_t t1 = msclock();
dumpdata* attack = (dumpdata* ) malloc(itemsize);
dumpdata* attack = (dumpdata* ) calloc(itemsize, sizeof(uint8_t));
for (i = 0 ; i * itemsize < dumpsize ; i++ ) {
memcpy(attack, dump + i * itemsize, itemsize);

View file

@ -215,11 +215,11 @@ const char *get_my_executable_directory(void) {
static void set_my_executable_path(void) {
int path_length = wai_getExecutablePath(NULL, 0, NULL);
if (path_length != -1) {
my_executable_path = (char*)malloc(path_length + 1);
my_executable_path = (char*)calloc(path_length + 1, sizeof(uint8_t));
int dirname_length = 0;
if (wai_getExecutablePath(my_executable_path, path_length, &dirname_length) != -1) {
my_executable_path[path_length] = '\0';
my_executable_directory = (char *)malloc(dirname_length + 2);
my_executable_directory = (char *)calloc(dirname_length + 2, sizeof(uint8_t));
strncpy(my_executable_directory, my_executable_path, dirname_length+1);
my_executable_directory[dirname_length+1] = '\0';
}
@ -321,9 +321,9 @@ int main(int argc, char* argv[]) {
} else {
if (addLuaExec){
// add "script run " to command
char *ctmp = NULL;
int len = strlen(script_cmd) + 11 + 1;
if ((ctmp = (char*) malloc(len)) != NULL) {
char *ctmp = (char*) calloc(len, sizeof(uint8_t));
if (ctmp != NULL) {
memset(ctmp, 0, len);
strcpy(ctmp, "script run ");
strcpy(&ctmp[11], script_cmd);

View file

@ -377,7 +377,9 @@ ipqx:
/* allocate argument array */
args = argc - optind;
if(!(apolys = malloc(args * sizeof(poly_t)))){
apolys = calloc(args * sizeof(poly_t), sizeof(char));
if ( !apolys ){
uerror("cannot allocate memory for argument list");
return 0;
}

View file

@ -118,7 +118,7 @@ char * mtostr(const model_t *model) {
+ (checkstr && *checkstr ? strlen(checkstr) : 6)
+ (magicstr && *magicstr ? strlen(magicstr) : 6)
+ (model->name && *model->name ? 2 + strlen(model->name) : 6);
if ((string = malloc(size))) {
if ((string = calloc(size, sizeof(uint8_t)))) {
sprintf(strbuf, "\"%s\"", model->name);
sprintf(string,
"width=%lu "

View file

@ -349,7 +349,7 @@ pxsubs(const poly_t poly, int flags, int bperhx, unsigned long start, unsigned l
size *= cperhx;
if(!size || ~flags & P_SPACE) ++size; /* for trailing null */
if(!(sptr = string = (char *) malloc(size)))
if(!(sptr = string = (char *) calloc(size, sizeof(char))))
uerror("cannot allocate memory for string");
size = end - start;

View file

@ -811,7 +811,9 @@ int mbynam(model_t *dest, const char *key) {
if (!aliases->name)
return(-1);
if (!(ukey = malloc((size_t) 1 + strlen(key) + 1))) {
ukey = calloc((size_t) 1 + strlen(key) + 1, sizeof(char));
if (!ukey) {
uerror("[!] cannot allocate memory for comparison string");
return(0);
}
@ -861,7 +863,9 @@ char * mnames(void) {
++aptr;
}
if (!size) return(NULL);
if ((string = malloc(size))) {
string = calloc(size, sizeof(char));
if (string) {
aptr = aliases;
sptr = string;
while (aptr->name) {

View file

@ -173,8 +173,9 @@ modpol(const poly_t init, int rflags, int args, const poly_t *argpolys) {
unsigned long alen, blen;
if(args < 2) return(NULL);
if(!(result = malloc(((((args - 1) * args) >> 1) + 1) * sizeof(poly_t))))
result = calloc(((((args - 1) * args) >> 1) + 1) * sizeof(poly_t), sizeof(char));
if(!result)
uerror("cannot allocate memory for codeword table");
rptr = result;
@ -240,7 +241,8 @@ engini(int *resc, model_t **result, const poly_t divisor, int flags, int args, c
dlen = plen(divisor);
/* Allocate the CRC matrix */
if(!(mat = (poly_t *) malloc((dlen << 1) * sizeof(poly_t))))
mat = (poly_t *) calloc((dlen << 1) * sizeof(poly_t), sizeof(char));
if(!mat)
uerror("cannot allocate memory for CRC matrix");
/* Find arguments of the two shortest lengths */

View file

@ -51,7 +51,8 @@ int scandir (const char *dir,
nl = ntmp;
}
if (!(etmp = (struct dirent *) malloc (sizeof *ent))) {
etmp = (struct dirent *) calloc (sizeof *ent, sizeof(char));
if (!etmp) {
err_no = 1;
break;
}

View file

@ -105,7 +105,7 @@ CborError _cbor_value_dup_string(const CborValue *value, void **buffer, size_t *
return err;
++*buflen;
*buffer = malloc(*buflen);
*buffer = calloc(*buflen, sizeof(uint8_t));
if (!*buffer) {
/* out of memory */
return CborErrorOutOfMemory;

View file

@ -178,7 +178,7 @@ static CborError dump_bytestring_base16(char **result, CborValue *it)
return err;
/* a Base16 (hex) output is twice as big as our buffer */
buffer = (uint8_t *)malloc(n * 2 + 1);
buffer = (uint8_t *)calloc(n * 2 + 1, sizeof(uint8_t));
*result = (char *)buffer;
/* let cbor_value_copy_byte_string know we have an extra byte for the terminating NUL */
@ -204,7 +204,7 @@ static CborError generic_dump_base64(char **result, CborValue *it, const char al
/* a Base64 output (untruncated) has 4 bytes for every 3 in the input */
size_t len = (n + 5) / 3 * 4;
out = buffer = (uint8_t *)malloc(len + 1);
out = buffer = (uint8_t *)calloc(len + 1, sizeof(uint8_t));
*result = (char *)buffer;
/* we read our byte string at the tail end of the buffer

View file

@ -280,7 +280,7 @@ void sprint_bin_break_ex(uint8_t *src, size_t srclen, char *dest , uint8_t break
printf("(sprint_bin_break) rowlen %d\n", rowlen);
// 3072 + end of line characters if broken at 8 bits
dest = (char *)malloc(MAX_BIN_BREAK_LENGTH);
dest = (char *)calloc(MAX_BIN_BREAK_LENGTH, sizeof(uint8_t));
if (dest == NULL) return;
//clear memory