From 3ab4e28666ab4b5ea32fe87795df0a9dad57a5ee Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Mon, 16 Nov 2020 11:45:41 +0900 Subject: [PATCH] rawmidi: check whether method argument for GError is available In Rules for use of GError, the check of arguments for GError may be preferable to avoid to unexpected function call. This commit adds the check. Reference: https://developer.gnome.org/glib/stable/glib-Error-Reporting.html Signed-off-by: Takashi Sakamoto --- src/rawmidi/query.c | 8 ++++++++ src/rawmidi/stream-pair.c | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/rawmidi/query.c b/src/rawmidi/query.c index 73c3ee0..8dd3f91 100644 --- a/src/rawmidi/query.c +++ b/src/rawmidi/query.c @@ -147,6 +147,7 @@ void alsarawmidi_get_device_id_list(guint card_id, guint **entries, g_return_if_fail(entries != NULL); g_return_if_fail(entry_count != NULL); + g_return_if_fail(error == NULL || *error == NULL); prepare_udev_enum(&enumerator, error); if (*error != NULL) @@ -224,6 +225,8 @@ void alsarawmidi_get_rawmidi_sysname(guint card_id, guint device_id, struct udev *ctx; struct udev_device *dev; + g_return_if_fail(error == NULL || *error == NULL); + length = strlen(RAWMIDI_SYSNAME_TEMPLATE) + calculate_digits(card_id) + calculate_digits(device_id) + 1; name = g_malloc0(length); @@ -269,6 +272,8 @@ void alsarawmidi_get_rawmidi_devnode(guint card_id, guint device_id, struct udev_device *dev; const char *node; + g_return_if_fail(error == NULL || *error == NULL); + length = strlen(RAWMIDI_SYSNAME_TEMPLATE) + calculate_digits(card_id) + calculate_digits(device_id) + 1; name = g_malloc0(length); @@ -382,6 +387,7 @@ void alsarawmidi_get_subdevice_id_list(guint card, guint device, g_return_if_fail(entries != NULL); g_return_if_fail(entry_count != NULL); + g_return_if_fail(error == NULL || *error == NULL); rawmidi_perform_ctl_ioctl(card, SNDRV_CTL_IOCTL_RAWMIDI_INFO, &info, error); if (*error != NULL) @@ -417,6 +423,8 @@ void alsarawmidi_get_substream_info(guint card_id, guint device_id, { struct snd_rawmidi_info *info; + g_return_if_fail(error == NULL || *error == NULL); + if (substream_info == NULL) { generate_error(error, EINVAL); return; diff --git a/src/rawmidi/stream-pair.c b/src/rawmidi/stream-pair.c index 61408e0..92f32f5 100644 --- a/src/rawmidi/stream-pair.c +++ b/src/rawmidi/stream-pair.c @@ -188,6 +188,8 @@ void alsarawmidi_stream_pair_open(ALSARawmidiStreamPair *self, guint card_id, g_return_if_fail(ALSARAWMIDI_IS_STREAM_PAIR(self)); priv = alsarawmidi_stream_pair_get_instance_private(self); + g_return_if_fail(error == NULL || *error == NULL); + // The flag is used to attach substreams for each direction. if (access_modes & ~(ALSARAWMIDI_STREAM_PAIR_INFO_FLAG_OUTPUT | ALSARAWMIDI_STREAM_PAIR_INFO_FLAG_INPUT)) { @@ -259,6 +261,8 @@ void alsarawmidi_stream_pair_get_protocol_version(ALSARawmidiStreamPair *self, g_return_if_fail(ALSARAWMIDI_IS_STREAM_PAIR(self)); priv = alsarawmidi_stream_pair_get_instance_private(self); + g_return_if_fail(error == NULL || *error == NULL); + if (priv->fd < 0) { generate_error(error, ENXIO); return; @@ -290,6 +294,8 @@ void alsarawmidi_stream_pair_get_substream_info(ALSARawmidiStreamPair *self, g_return_if_fail(ALSARAWMIDI_IS_STREAM_PAIR(self)); priv = alsarawmidi_stream_pair_get_instance_private(self); + g_return_if_fail(error == NULL || *error == NULL); + *substream_info = g_object_new(ALSARAWMIDI_TYPE_SUBSTREAM_INFO, NULL); rawmidi_substream_info_refer_private(*substream_info, &info); @@ -325,6 +331,8 @@ void alsarawmidi_stream_pair_set_substream_params(ALSARawmidiStreamPair *self, g_return_if_fail(ALSARAWMIDI_IS_STREAM_PAIR(self)); priv = alsarawmidi_stream_pair_get_instance_private(self); + g_return_if_fail(error == NULL || *error == NULL); + rawmidi_substream_params_refer_private(substream_params, ¶ms); params->stream = direction; @@ -357,6 +365,8 @@ void alsarawmidi_stream_pair_get_substream_status(ALSARawmidiStreamPair *self, g_return_if_fail(substream_status != NULL); priv = alsarawmidi_stream_pair_get_instance_private(self); + g_return_if_fail(error == NULL || *error == NULL); + rawmidi_substream_status_refer_private(*substream_status, &status); status->stream = direction; @@ -389,6 +399,8 @@ void alsarawmidi_stream_pair_read_from_substream(ALSARawmidiStreamPair *self, g_return_if_fail(ALSARAWMIDI_IS_STREAM_PAIR(self)); priv = alsarawmidi_stream_pair_get_instance_private(self); + g_return_if_fail(error == NULL || *error == NULL); + len = read(priv->fd, *buf, *buf_size); if (len < 0) { generate_error(error, errno); @@ -423,6 +435,8 @@ void alsarawmidi_stream_pair_write_to_substream(ALSARawmidiStreamPair *self, g_return_if_fail(ALSARAWMIDI_IS_STREAM_PAIR(self)); priv = alsarawmidi_stream_pair_get_instance_private(self); + g_return_if_fail(error == NULL || *error == NULL); + len = write(priv->fd, buf, buf_size); if (len < 0) { generate_error(error, errno); @@ -453,6 +467,8 @@ void alsarawmidi_stream_pair_drain_substream(ALSARawmidiStreamPair *self, g_return_if_fail(ALSARAWMIDI_IS_STREAM_PAIR(self)); priv = alsarawmidi_stream_pair_get_instance_private(self); + g_return_if_fail(error == NULL || *error == NULL); + if (ioctl(priv->fd, SNDRV_RAWMIDI_IOCTL_DRAIN, &direction) < 0) generate_error(error, errno); } @@ -479,6 +495,8 @@ void alsarawmidi_stream_pair_drop_substream(ALSARawmidiStreamPair *self, g_return_if_fail(ALSARAWMIDI_IS_STREAM_PAIR(self)); priv = alsarawmidi_stream_pair_get_instance_private(self); + g_return_if_fail(error == NULL || *error == NULL); + if (ioctl(priv->fd, SNDRV_RAWMIDI_IOCTL_DROP, &direction) < 0) generate_error(error, errno); } @@ -557,6 +575,8 @@ void alsarawmidi_stream_pair_create_source(ALSARawmidiStreamPair *self, g_return_if_fail(ALSARAWMIDI_IS_STREAM_PAIR(self)); priv = alsarawmidi_stream_pair_get_instance_private(self); + g_return_if_fail(error == NULL || *error == NULL); + if (priv->fd < 0) { generate_error(error, ENXIO); return; -- 2.47.3