From 2a48b34bcd6ffe189684e87441f430fc983fe1cd Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Mon, 12 Jul 2010 19:37:31 +0000 Subject: [PATCH] Changed all malloc() to calloc() --- cdrskin/cdrskin_timestamp.h | 2 +- libburn/async.c | 2 +- libburn/drive.c | 9 +++------ libburn/file.c | 6 +++--- libburn/libdax_audioxtr.c | 2 +- libburn/libdax_msgs.c | 6 +++--- libburn/mmc.c | 2 +- libburn/null.c | 2 +- libburn/options.c | 6 +++--- libburn/read.c | 3 --- libburn/sg-freebsd-port.c | 5 +++-- libburn/sg-freebsd.c | 14 +++++++------- libburn/util.c | 4 ++-- 13 files changed, 29 insertions(+), 34 deletions(-) diff --git a/cdrskin/cdrskin_timestamp.h b/cdrskin/cdrskin_timestamp.h index ce35aa5..b94ffad 100644 --- a/cdrskin/cdrskin_timestamp.h +++ b/cdrskin/cdrskin_timestamp.h @@ -1 +1 @@ -#define Cdrskin_timestamP "2010.07.12.193201" +#define Cdrskin_timestamP "2010.07.12.193644" diff --git a/libburn/async.c b/libburn/async.c index e75ad59..60818bf 100644 --- a/libburn/async.c +++ b/libburn/async.c @@ -143,7 +143,7 @@ static void add_worker(int w_type, struct burn_drive *d, pthread_attr_t attr; #endif - a = malloc(sizeof(struct w_list)); + a = calloc(1, sizeof(struct w_list)); a->w_type = w_type; a->drive = d; a->u = *(union w_list_data *)data; diff --git a/libburn/drive.c b/libburn/drive.c index bb5541e..ce03573 100644 --- a/libburn/drive.c +++ b/libburn/drive.c @@ -12,9 +12,6 @@ #include #include - -/* #include ts A61013 : not in GNU/Linux man 3 malloc */ - #include #include #include @@ -1297,7 +1294,7 @@ int burn_drive_add_whitelist(char *device_address) if(enumeration_whitelist_top+1 >= BURN_DRIVE_WHITELIST_LEN) return 0; enumeration_whitelist_top++; - new_item = malloc(strlen(device_address) + 1); + new_item = calloc(1, strlen(device_address) + 1); if (new_item == NULL) return -1; strcpy(new_item, device_address); @@ -2221,7 +2218,7 @@ int burn_speed_descriptor_new(struct burn_speed_descriptor **s, { struct burn_speed_descriptor *o; - (*s) = o = malloc(sizeof(struct burn_speed_descriptor)); + (*s) = o = calloc(1, sizeof(struct burn_speed_descriptor)); if (o == NULL) return -1; o->source = 0; @@ -2392,7 +2389,7 @@ int burn_disc_get_multi_caps(struct burn_drive *d, enum burn_write_types wt, if(s == BURN_DISC_UNGRABBED) return -1; *caps = o = (struct burn_multi_caps *) - malloc(sizeof(struct burn_multi_caps)); + calloc(1, sizeof(struct burn_multi_caps)); if(*caps == NULL) return -1; /* Default says nothing is available */ diff --git a/libburn/file.c b/libburn/file.c index a5286b0..b831560 100644 --- a/libburn/file.c +++ b/libburn/file.c @@ -129,7 +129,7 @@ struct burn_source *burn_file_source_new(const char *path, const char *subpath) return NULL; } } - fs = malloc(sizeof(struct burn_source_file)); + fs = calloc(1, sizeof(struct burn_source_file)); /* ts A70825 */ if (fs == NULL) { @@ -175,7 +175,7 @@ struct burn_source *burn_fd_source_new(int datafd, int subfd, off_t size) if (datafd == -1) return NULL; - fs = malloc(sizeof(struct burn_source_file)); + fs = calloc(1, sizeof(struct burn_source_file)); if (fs == NULL) /* ts A70825 */ return NULL; fs->datafd = datafd; @@ -508,7 +508,7 @@ struct burn_source *burn_fifo_source_new(struct burn_source *inp, "Desired fifo buffer too small", 0, 0); return NULL; } - fs = malloc(sizeof(struct burn_source_fifo)); + fs = calloc(1, sizeof(struct burn_source_fifo)); if (fs == NULL) return NULL; fs->is_started = 0; diff --git a/libburn/libdax_audioxtr.c b/libburn/libdax_audioxtr.c index 841f0c1..0eb8960 100644 --- a/libburn/libdax_audioxtr.c +++ b/libburn/libdax_audioxtr.c @@ -35,7 +35,7 @@ int libdax_audioxtr_new(struct libdax_audioxtr **xtr, char *path, int flag) int ret= -1; struct libdax_audioxtr *o; - o= *xtr= (struct libdax_audioxtr *) malloc(sizeof(struct libdax_audioxtr)); + o= *xtr= (struct libdax_audioxtr *) calloc(1, sizeof(struct libdax_audioxtr)); if(o==NULL) return(-1); strncpy(o->path,path,LIBDAX_AUDIOXTR_STRLEN-1); diff --git a/libburn/libdax_msgs.c b/libburn/libdax_msgs.c index 28bbb9a..5d67715 100644 --- a/libburn/libdax_msgs.c +++ b/libburn/libdax_msgs.c @@ -37,7 +37,7 @@ static int libdax_msgs_item_new(struct libdax_msgs_item **item, struct timezone tz; (*item)= o= - (struct libdax_msgs_item *) malloc(sizeof(struct libdax_msgs_item)); + (struct libdax_msgs_item *) calloc(1, sizeof(struct libdax_msgs_item)); if(o==NULL) return(-1); o->timestamp= 0.0; @@ -140,7 +140,7 @@ int libdax_msgs_new(struct libdax_msgs **m, int flag) { struct libdax_msgs *o; - (*m)= o= (struct libdax_msgs *) malloc(sizeof(struct libdax_msgs)); + (*m)= o= (struct libdax_msgs *) calloc(1, sizeof(struct libdax_msgs)); if(o==NULL) return(-1); o->refcount= 1; @@ -370,7 +370,7 @@ int libdax_msgs_submit(struct libdax_msgs *m, int origin, int error_code, item->severity= severity; item->priority= priority; if(msg_text!=NULL) { - item->msg_text= malloc(strlen(msg_text)+1); + item->msg_text= calloc(1, strlen(msg_text)+1); if(item->msg_text==NULL) goto failed; strcpy(item->msg_text,msg_text); diff --git a/libburn/mmc.c b/libburn/mmc.c index 59b6292..b42832a 100644 --- a/libburn/mmc.c +++ b/libburn/mmc.c @@ -1165,7 +1165,7 @@ int mmc_fake_toc(struct burn_drive *d) if (d->disc == NULL) return -1; d->toc_entries = d->last_track_no + d->complete_sessions; - d->toc_entry = malloc(d->toc_entries * sizeof(struct burn_toc_entry)); + d->toc_entry = calloc(d->toc_entries, sizeof(struct burn_toc_entry)); if (d->toc_entry == NULL) return -1; memset(d->toc_entry, 0,d->toc_entries * sizeof(struct burn_toc_entry)); diff --git a/libburn/null.c b/libburn/null.c index 278d360..71e102e 100644 --- a/libburn/null.c +++ b/libburn/null.c @@ -24,7 +24,7 @@ struct burn_source *burn_null_source_new(void) { struct burn_source *src; - src = malloc(sizeof(struct burn_source)); + src = calloc(1, sizeof(struct burn_source)); src->refcount = 1; src->read = null_read; src->read_sub = NULL; diff --git a/libburn/options.c b/libburn/options.c index 4b4aa61..58c4136 100644 --- a/libburn/options.c +++ b/libburn/options.c @@ -27,7 +27,7 @@ struct burn_write_opts *burn_write_opts_new(struct burn_drive *drive) { struct burn_write_opts *opts; - opts = malloc(sizeof(struct burn_write_opts)); + opts = calloc(1, sizeof(struct burn_write_opts)); if (opts == NULL) { libdax_msgs_submit(libdax_messenger, -1, 0x00020111, LIBDAX_MSGS_SEV_FATAL, LIBDAX_MSGS_PRIO_HIGH, @@ -68,7 +68,7 @@ struct burn_read_opts *burn_read_opts_new(struct burn_drive *drive) { struct burn_read_opts *opts; - opts = malloc(sizeof(struct burn_read_opts)); + opts = calloc(1, sizeof(struct burn_read_opts)); opts->drive = drive; opts->refcount = 1; opts->raw = 0; @@ -125,7 +125,7 @@ void burn_write_opts_set_toc_entries(struct burn_write_opts *opts, int count, struct burn_toc_entry *toc_entries) { opts->toc_entries = count; - opts->toc_entry = malloc(count * sizeof(struct burn_toc_entry)); + opts->toc_entry = calloc(count, sizeof(struct burn_toc_entry)); memcpy(opts->toc_entry, &toc_entries, sizeof(struct burn_toc_entry) * count); } diff --git a/libburn/read.c b/libburn/read.c index 5840f34..f2e10d4 100644 --- a/libburn/read.c +++ b/libburn/read.c @@ -9,9 +9,6 @@ #include "../config.h" #endif - -/* #include ts A61013 : not in GNU/Linux man 3 malloc */ - #include #include #include diff --git a/libburn/sg-freebsd-port.c b/libburn/sg-freebsd-port.c index 1270192..16700e8 100644 --- a/libburn/sg-freebsd-port.c +++ b/libburn/sg-freebsd-port.c @@ -169,9 +169,10 @@ static int sg_init_enumerator(burn_drive_enumerator_t *idx) idx->ccb.ccb_h.func_code = XPT_DEV_MATCH; idx->bufsize = sizeof(struct dev_match_result) * 100; idx->ccb.cdm.match_buf_len = idx->bufsize; - idx->ccb.cdm.matches = (struct dev_match_result *)malloc(idx->bufsize); + idx->ccb.cdm.matches = (struct dev_match_result *) + calloc(1, idx->bufsize); if (idx->ccb.cdm.matches == NULL) { - warnx("can't malloc memory for matches"); + warnx("cannot allocate memory for matches"); close(idx->fd); return -1; } diff --git a/libburn/sg-freebsd.c b/libburn/sg-freebsd.c index 25a2392..7385133 100644 --- a/libburn/sg-freebsd.c +++ b/libburn/sg-freebsd.c @@ -160,15 +160,15 @@ static int sg_init_enumerator(burn_drive_enumerator_t *idx_) struct burn_drive_enumeration_state *idx; int bufsize; - idx = malloc(sizeof(*idx)); + idx = calloc(1, sizeof(*idx)); if (idx == NULL) { - warnx("can't malloc memory for enumerator"); + warnx("cannot allocate memory for enumerator"); return -1; } idx->skip_device = 0; if ((idx->fd = open(XPT_DEVICE, O_RDWR)) == -1) { - warn("couldn't open %s", XPT_DEVICE); + warn("could not open %s", XPT_DEVICE); free(idx); idx = NULL; return -1; @@ -183,9 +183,9 @@ static int sg_init_enumerator(burn_drive_enumerator_t *idx_) idx->ccb.ccb_h.func_code = XPT_DEV_MATCH; bufsize = sizeof(struct dev_match_result) * 100; idx->ccb.cdm.match_buf_len = bufsize; - idx->ccb.cdm.matches = (struct dev_match_result *)malloc(bufsize); + idx->ccb.cdm.matches = (struct dev_match_result *) calloc(1, bufsize); if (idx->ccb.cdm.matches == NULL) { - warnx("can't malloc memory for matches"); + warnx("cannot allocate memory for matches"); close(idx->fd); free(idx); return -1; @@ -487,9 +487,9 @@ static void enumerate_common(char *fname, int bus_no, int host_no, out.close_session = mmc_close_session; out.close_track_session = mmc_close; out.read_buffer_capacity = mmc_read_buffer_capacity; - out.idata = malloc(sizeof(struct burn_scsi_inquiry_data)); + out.idata = calloc(1, sizeof(struct burn_scsi_inquiry_data)); out.idata->valid = 0; - out.mdata = malloc(sizeof(struct scsi_mode_data)); + out.mdata = calloc(1, sizeof(struct scsi_mode_data)); out.mdata->valid = 0; if (out.idata == NULL || out.mdata == NULL) { libdax_msgs_submit(libdax_messenger, -1, 0x00020108, diff --git a/libburn/util.c b/libburn/util.c index 0de4908..3fd70c7 100644 --- a/libburn/util.c +++ b/libburn/util.c @@ -34,7 +34,7 @@ char *burn_strdup(char *s) return NULL; l = strlen(s) + 1; - ret = malloc(l); + ret = calloc(1, l); memcpy(ret, s, l); return ret; @@ -52,7 +52,7 @@ char *burn_strndup(char *s, int n) return NULL; l = strlen(s); - ret = malloc(l < n ? l : n); + ret = calloc(1, l < n ? l : n); memcpy(ret, s, l < n - 1 ? l : n - 1); ret[n - 1] = '\0';