From: Johannes W. <ja...@mo...> - 2011-05-05 15:20:02
|
Setting memory of pointers to 0 violates the C standard. Also this solution is more readable! --- aac.c | 11 +++++++---- flac.c | 16 ++++++++++------ mp4.c | 6 +++++- mpc.c | 25 +++++++++++++++---------- nomad.c | 14 +++++++++++--- wavpack.c | 12 +++++++++--- 6 files changed, 57 insertions(+), 27 deletions(-) diff --git a/aac.c b/aac.c index 56d4bc5..3b3552a 100644 --- a/aac.c +++ b/aac.c @@ -193,10 +193,13 @@ static int aac_open(struct input_plugin_data *ip_data) int ret, n; /* init private struct */ - priv = xnew0(struct aac_private, 1); - priv->decoder = NeAACDecOpen(); - priv->bitrate = -1; - priv->object_type = -1; + const struct aac_private priv_init = { + .decoder = NeAACDecOpen(), + .bitrate = -1, + .object_type = -1 + }; + priv = xnew(struct aac_private, 1); + *priv = priv_init; ip_data->private = priv; /* set decoder config */ diff --git a/flac.c b/flac.c index 3b02a77..64b1d0d 100644 --- a/flac.c +++ b/flac.c @@ -378,15 +378,19 @@ static void free_priv(struct input_plugin_data *ip_data) static int flac_open(struct input_plugin_data *ip_data) { struct flac_private *priv; - Dec *dec; - dec = F(new)(); - if (dec == NULL) + Dec *dec = F(new)(); + + const struct flac_private priv_init = { + .dec = dec, + .duration = -1 + }; + + if (!dec) return -IP_ERROR_INTERNAL; - priv = xnew0(struct flac_private, 1); - priv->dec = dec; - priv->duration = -1; + priv = xnew(struct flac_private, 1); + *priv = priv_init; if (ip_data->remote) { priv->len = UINT64_MAX; } else { diff --git a/mp4.c b/mp4.c index 43b20b8..8afc5fe 100644 --- a/mp4.c +++ b/mp4.c @@ -99,13 +99,17 @@ static int mp4_open(struct input_plugin_data *ip_data) unsigned int buf_size; int rc = -IP_ERROR_FILE_FORMAT; + const struct mp4_private priv_init = { + .decoder = NULL + }; /* http://sourceforge.net/forum/message.php?msg_id=3578887 */ if (ip_data->remote) return -IP_ERROR_FUNCTION_NOT_SUPPORTED; /* init private struct */ - priv = xnew0(struct mp4_private, 1); + priv = xnew(struct mp4_private, 1); + *priv = priv_init; ip_data->private = priv; priv->decoder = NeAACDecOpen(); diff --git a/mpc.c b/mpc.c index cff2387..8320191 100644 --- a/mpc.c +++ b/mpc.c @@ -123,22 +123,27 @@ static int mpc_open(struct input_plugin_data *ip_data) { struct mpc_private *priv; - priv = xnew0(struct mpc_private, 1); + const struct mpc_private priv_init = { + .file_size = -1, + /* set up an mpc_reader linked to our function implementations */ + .reader = { + .read = read_impl, + .seek = seek_impl, + .tell = tell_impl, + .get_size = get_size_impl, + .canseek = canseek_impl, + .data = ip_data + } + }; + + priv = xnew(struct mpc_private, 1); + *priv = priv_init; - priv->file_size = -1; if (!ip_data->remote) { priv->file_size = lseek(ip_data->fd, 0, SEEK_END); lseek(ip_data->fd, 0, SEEK_SET); } - /* set up an mpc_reader linked to our function implementations */ - priv->reader.read = read_impl; - priv->reader.seek = seek_impl; - priv->reader.tell = tell_impl; - priv->reader.get_size = get_size_impl; - priv->reader.canseek = canseek_impl; - priv->reader.data = ip_data; - /* must be before mpc_streaminfo_read() */ ip_data->private = priv; diff --git a/nomad.c b/nomad.c index 453ee07..e892d78 100644 --- a/nomad.c +++ b/nomad.c @@ -585,9 +585,17 @@ int nomad_open_callbacks(struct nomad **nomadp, void *datasource, struct nomad_c { struct nomad *nomad; - nomad = xnew0(struct nomad, 1); - nomad->datasource = datasource; - nomad->cbs = *cbs; + const struct nomad nomad_init = { + .datasource = datasource, + .cbs = { + .read = cbs->read, + .lseek = cbs->lseek, + .close = cbs->close + } + }; + + nomad = xnew(struct nomad, 1); + *nomad = nomad_init; nomad->lame.peak = nomad->lame.trackGain = nomad->lame.albumGain = strtof("NAN", NULL); *nomadp = nomad; /* on error do_open calls nomad_close */ diff --git a/wavpack.c b/wavpack.c index 9d57400..257d5b5 100644 --- a/wavpack.c +++ b/wavpack.c @@ -165,9 +165,15 @@ static int wavpack_open(struct input_plugin_data *ip_data) struct stat st; char msg[80]; - priv = xnew0(struct wavpack_private, 1); - priv->wv_file.fd = ip_data->fd; - priv->wv_file.push_back_byte = EOF; + const struct wavpack_private priv_init = { + .wv_file = { + .fd = ip_data->fd, + .push_back_byte = EOF + } + }; + + priv = xnew(struct wavpack_private, 1); + *priv = priv_init; if (!ip_data->remote && fstat(ip_data->fd, &st) == 0) { char *filename_wvc; -- 1.7.5 |