Use calloc instead of malloc + memset

svn path=/trunk/; revision=59548
This commit is contained in:
Pierre Schweitzer 2013-07-21 16:15:16 +00:00
parent fe0958fb25
commit 6243e7c650
2 changed files with 5 additions and 10 deletions

View file

@ -652,10 +652,9 @@ new_directory_record (struct _finddata_t *f,
{ {
PDIR_RECORD d; PDIR_RECORD d;
d = malloc(sizeof(DIR_RECORD)); d = calloc(1, sizeof(DIR_RECORD));
if (d == NULL) if (d == NULL)
error_exit("Insufficient memory"); error_exit("Insufficient memory");
memset ( d, 0, sizeof(DIR_RECORD) );
d->next_in_memory = root.next_in_memory; d->next_in_memory = root.next_in_memory;
root.next_in_memory = d; root.next_in_memory = d;
@ -687,10 +686,9 @@ new_directory_record (struct dirent *entry,
char *n; char *n;
*/ */
d = malloc(sizeof(DIR_RECORD)); d = calloc(1, sizeof(DIR_RECORD));
if (d == NULL) if (d == NULL)
error_exit("Insufficient memory"); error_exit("Insufficient memory");
memset ( d, 0, sizeof(DIR_RECORD) );
d->next_in_memory = root.next_in_memory; d->next_in_memory = root.next_in_memory;
root.next_in_memory = d; root.next_in_memory = d;
@ -1071,8 +1069,7 @@ static PDIR_RECORD
new_empty_dirrecord(PDIR_RECORD d, BOOL directory) new_empty_dirrecord(PDIR_RECORD d, BOOL directory)
{ {
PDIR_RECORD new_d; PDIR_RECORD new_d;
new_d = malloc(sizeof(*new_d)); new_d = calloc(1, sizeof(*new_d));
memset(new_d, 0, sizeof(*new_d));
new_d->parent = d; new_d->parent = d;
new_d->level = d->level + 1; new_d->level = d->level + 1;
new_d->next_in_directory = d->first_record; new_d->next_in_directory = d->first_record;

View file

@ -111,8 +111,7 @@ dir_hash_create_dir(struct target_dir_hash *dh, const char *casename, const char
free(parentname); free(parentname);
free(parentcase); free(parentcase);
hashcode = djb_hash(targetnorm); hashcode = djb_hash(targetnorm);
de = malloc(sizeof(*de)); de = calloc(1, sizeof(*de));
memset(de, 0, sizeof(*de));
de->parent = parent_de; de->parent = parent_de;
de->normalized_name = strdup(targetnorm); de->normalized_name = strdup(targetnorm);
de->case_name = strdup(chop_filename(casename)); de->case_name = strdup(chop_filename(casename));
@ -139,8 +138,7 @@ void dir_hash_add_file(struct target_dir_hash *dh, const char *source, const cha
targetnorm = strdup(targetdir); targetnorm = strdup(targetdir);
normalize_dirname(targetnorm); normalize_dirname(targetnorm);
de = dir_hash_create_dir(dh, targetdir, targetnorm); de = dir_hash_create_dir(dh, targetdir, targetnorm);
tf = malloc(sizeof(*tf)); tf = calloc(1, sizeof(*tf));
memset(tf, 0, sizeof(*tf));
tf->next = de->head; tf->next = de->head;
de->head = tf; de->head = tf;
tf->source_name = strdup(source); tf->source_name = strdup(source);