summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Ratajsky <[email protected]>2016-01-04 20:31:14 +0100
committerMichal Ratajsky <[email protected]>2016-01-04 20:31:14 +0100
commit9772797c31ebed2417b42a9389caae1b16847e86 (patch)
tree0257271d6f8387ce89984bf8341b11186381c8d5
parentd32ca3f420d036cd750fc1aad7f95da40559cc5d (diff)
downloadlibmatemixer-9772797c31ebed2417b42a9389caae1b16847e86.tar.bz2
libmatemixer-9772797c31ebed2417b42a9389caae1b16847e86.tar.xz
Improve error checking in many places
-rw-r--r--backends/alsa/alsa-stream-control.c8
-rw-r--r--backends/alsa/alsa-stream-input-control.c16
-rw-r--r--backends/alsa/alsa-stream-output-control.c15
-rw-r--r--backends/alsa/alsa-stream.c8
-rw-r--r--backends/alsa/alsa-switch-option.c3
-rw-r--r--backends/alsa/alsa-toggle.c8
-rw-r--r--backends/oss/oss-backend.c16
-rw-r--r--backends/oss/oss-device.c12
-rw-r--r--backends/oss/oss-stream-control.c18
-rw-r--r--backends/oss/oss-stream.c10
-rw-r--r--backends/oss/oss-switch-option.c3
-rw-r--r--backends/oss/oss-switch.c11
-rw-r--r--backends/pulse/pulse-connection.c12
-rw-r--r--backends/pulse/pulse-device-switch.c4
-rw-r--r--backends/pulse/pulse-device.c1
-rw-r--r--backends/pulse/pulse-ext-stream.c8
-rw-r--r--backends/pulse/pulse-helpers.c2
-rw-r--r--backends/pulse/pulse-sink-input.c8
-rw-r--r--backends/pulse/pulse-sink-switch.c5
-rw-r--r--backends/pulse/pulse-sink.c6
-rw-r--r--backends/pulse/pulse-source-output.c8
-rw-r--r--backends/pulse/pulse-source-switch.c5
-rw-r--r--backends/pulse/pulse-source.c6
-rw-r--r--backends/pulse/pulse-stream-control.c14
-rw-r--r--backends/pulse/pulse-stream-control.h3
-rw-r--r--libmatemixer/matemixer-backend.c2
-rw-r--r--libmatemixer/matemixer-device.c6
-rw-r--r--libmatemixer/matemixer-stream-control.c2
-rw-r--r--libmatemixer/matemixer-switch.c1
29 files changed, 187 insertions, 34 deletions
diff --git a/backends/alsa/alsa-stream-control.c b/backends/alsa/alsa-stream-control.c
index 6e09a09..5fd643e 100644
--- a/backends/alsa/alsa-stream-control.c
+++ b/backends/alsa/alsa-stream-control.c
@@ -649,24 +649,32 @@ alsa_stream_control_set_fade (MateMixerStreamControl *mmsc, gfloat fade)
static guint
alsa_stream_control_get_min_volume (MateMixerStreamControl *mmsc)
{
+ g_return_val_if_fail (ALSA_IS_STREAM_CONTROL (mmsc), 0);
+
return ALSA_STREAM_CONTROL (mmsc)->priv->data.min;
}
static guint
alsa_stream_control_get_max_volume (MateMixerStreamControl *mmsc)
{
+ g_return_val_if_fail (ALSA_IS_STREAM_CONTROL (mmsc), 0);
+
return ALSA_STREAM_CONTROL (mmsc)->priv->data.max;
}
static guint
alsa_stream_control_get_normal_volume (MateMixerStreamControl *mmsc)
{
+ g_return_val_if_fail (ALSA_IS_STREAM_CONTROL (mmsc), 0);
+
return ALSA_STREAM_CONTROL (mmsc)->priv->data.max;
}
static guint
alsa_stream_control_get_base_volume (MateMixerStreamControl *mmsc)
{
+ g_return_val_if_fail (ALSA_IS_STREAM_CONTROL (mmsc), 0);
+
return ALSA_STREAM_CONTROL (mmsc)->priv->data.max;
}
diff --git a/backends/alsa/alsa-stream-input-control.c b/backends/alsa/alsa-stream-input-control.c
index 1954008..5f5e90e 100644
--- a/backends/alsa/alsa-stream-input-control.c
+++ b/backends/alsa/alsa-stream-input-control.c
@@ -25,6 +25,7 @@
#include "alsa-compat.h"
#include "alsa-constants.h"
#include "alsa-element.h"
+#include "alsa-stream.h"
#include "alsa-stream-control.h"
#include "alsa-stream-input-control.h"
@@ -82,6 +83,11 @@ alsa_stream_input_control_new (const gchar *name,
MateMixerStreamControlRole role,
AlsaStream *stream)
{
+
+ g_return_val_if_fail (name != NULL, NULL);
+ g_return_val_if_fail (label != NULL, NULL);
+ g_return_val_if_fail (ALSA_IS_STREAM (stream), NULL);
+
return g_object_new (ALSA_TYPE_STREAM_INPUT_CONTROL,
"name", name,
"label", label,
@@ -133,7 +139,7 @@ alsa_stream_input_control_set_mute (AlsaStreamControl *control, gboolean mute)
snd_mixer_elem_t *el;
gint ret;
- g_return_val_if_fail (ALSA_IS_STREAM_CONTROL (control), FALSE);
+ g_return_val_if_fail (ALSA_IS_STREAM_INPUT_CONTROL (control), FALSE);
el = alsa_element_get_snd_element (ALSA_ELEMENT (control));
if G_UNLIKELY (el == NULL)
@@ -154,7 +160,7 @@ alsa_stream_input_control_set_volume (AlsaStreamControl *control, guint volume)
snd_mixer_elem_t *el;
gint ret;
- g_return_val_if_fail (ALSA_IS_STREAM_CONTROL (control), FALSE);
+ g_return_val_if_fail (ALSA_IS_STREAM_INPUT_CONTROL (control), FALSE);
el = alsa_element_get_snd_element (ALSA_ELEMENT (control));
if G_UNLIKELY (el == NULL)
@@ -177,7 +183,7 @@ alsa_stream_input_control_set_channel_volume (AlsaStreamControl *contr
snd_mixer_elem_t *el;
gint ret;
- g_return_val_if_fail (ALSA_IS_STREAM_CONTROL (control), FALSE);
+ g_return_val_if_fail (ALSA_IS_STREAM_INPUT_CONTROL (control), FALSE);
el = alsa_element_get_snd_element (ALSA_ELEMENT (control));
if G_UNLIKELY (el == NULL)
@@ -202,7 +208,7 @@ alsa_stream_input_control_get_volume_from_decibel (AlsaStreamControl *control,
glong value;
gint ret;
- g_return_val_if_fail (ALSA_IS_STREAM_CONTROL (control), FALSE);
+ g_return_val_if_fail (ALSA_IS_STREAM_INPUT_CONTROL (control), FALSE);
el = alsa_element_get_snd_element (ALSA_ELEMENT (control));
if G_UNLIKELY (el == NULL)
@@ -231,7 +237,7 @@ alsa_stream_input_control_get_decibel_from_volume (AlsaStreamControl *control,
glong value;
gint ret;
- g_return_val_if_fail (ALSA_IS_STREAM_CONTROL (control), FALSE);
+ g_return_val_if_fail (ALSA_IS_STREAM_INPUT_CONTROL (control), FALSE);
el = alsa_element_get_snd_element (ALSA_ELEMENT (control));
if G_UNLIKELY (el == NULL)
diff --git a/backends/alsa/alsa-stream-output-control.c b/backends/alsa/alsa-stream-output-control.c
index 5b6a1eb..9d7813d 100644
--- a/backends/alsa/alsa-stream-output-control.c
+++ b/backends/alsa/alsa-stream-output-control.c
@@ -25,6 +25,7 @@
#include "alsa-compat.h"
#include "alsa-constants.h"
#include "alsa-element.h"
+#include "alsa-stream.h"
#include "alsa-stream-control.h"
#include "alsa-stream-output-control.h"
@@ -82,6 +83,10 @@ alsa_stream_output_control_new (const gchar *name,
MateMixerStreamControlRole role,
AlsaStream *stream)
{
+ g_return_val_if_fail (name != NULL, NULL);
+ g_return_val_if_fail (label != NULL, NULL);
+ g_return_val_if_fail (ALSA_IS_STREAM (stream), NULL);
+
return g_object_new (ALSA_TYPE_STREAM_OUTPUT_CONTROL,
"name", name,
"label", label,
@@ -133,7 +138,7 @@ alsa_stream_output_control_set_mute (AlsaStreamControl *control, gboolean mute)
snd_mixer_elem_t *el;
gint ret;
- g_return_val_if_fail (ALSA_IS_STREAM_CONTROL (control), FALSE);
+ g_return_val_if_fail (ALSA_IS_STREAM_OUTPUT_CONTROL (control), FALSE);
el = alsa_element_get_snd_element (ALSA_ELEMENT (control));
if G_UNLIKELY (el == NULL)
@@ -154,7 +159,7 @@ alsa_stream_output_control_set_volume (AlsaStreamControl *control, guint volume)
snd_mixer_elem_t *el;
gint ret;
- g_return_val_if_fail (ALSA_IS_STREAM_CONTROL (control), FALSE);
+ g_return_val_if_fail (ALSA_IS_STREAM_OUTPUT_CONTROL (control), FALSE);
el = alsa_element_get_snd_element (ALSA_ELEMENT (control));
if G_UNLIKELY (el == NULL)
@@ -177,7 +182,7 @@ alsa_stream_output_control_set_channel_volume (AlsaStreamControl *cont
snd_mixer_elem_t *el;
gint ret;
- g_return_val_if_fail (ALSA_IS_STREAM_CONTROL (control), FALSE);
+ g_return_val_if_fail (ALSA_IS_STREAM_OUTPUT_CONTROL (control), FALSE);
el = alsa_element_get_snd_element (ALSA_ELEMENT (control));
if G_UNLIKELY (el == NULL)
@@ -202,7 +207,7 @@ alsa_stream_output_control_get_volume_from_decibel (AlsaStreamControl *control,
glong value;
gint ret;
- g_return_val_if_fail (ALSA_IS_STREAM_CONTROL (control), FALSE);
+ g_return_val_if_fail (ALSA_IS_STREAM_OUTPUT_CONTROL (control), FALSE);
el = alsa_element_get_snd_element (ALSA_ELEMENT (control));
if G_UNLIKELY (el == NULL)
@@ -231,7 +236,7 @@ alsa_stream_output_control_get_decibel_from_volume (AlsaStreamControl *control,
glong value;
gint ret;
- g_return_val_if_fail (ALSA_IS_STREAM_CONTROL (control), FALSE);
+ g_return_val_if_fail (ALSA_IS_STREAM_OUTPUT_CONTROL (control), FALSE);
el = alsa_element_get_snd_element (ALSA_ELEMENT (control));
if G_UNLIKELY (el == NULL)
diff --git a/backends/alsa/alsa-stream.c b/backends/alsa/alsa-stream.c
index bce66ec..fc72f65 100644
--- a/backends/alsa/alsa-stream.c
+++ b/backends/alsa/alsa-stream.c
@@ -20,6 +20,7 @@
#include <libmatemixer/matemixer.h>
#include <libmatemixer/matemixer-private.h>
+#include "alsa-device.h"
#include "alsa-element.h"
#include "alsa-stream.h"
#include "alsa-stream-control.h"
@@ -94,7 +95,12 @@ alsa_stream_new (const gchar *name,
MateMixerDevice *device,
MateMixerDirection direction)
{
- const gchar *label = mate_mixer_device_get_label (device);
+ const gchar *label;
+
+ g_return_val_if_fail (name != NULL, NULL);
+ g_return_val_if_fail (ALSA_IS_DEVICE (device), NULL);
+
+ label = mate_mixer_device_get_label (device);
return g_object_new (ALSA_TYPE_STREAM,
"name", name,
diff --git a/backends/alsa/alsa-switch-option.c b/backends/alsa/alsa-switch-option.c
index 1800df2..81326ce 100644
--- a/backends/alsa/alsa-switch-option.c
+++ b/backends/alsa/alsa-switch-option.c
@@ -54,6 +54,9 @@ alsa_switch_option_new (const gchar *name,
{
AlsaSwitchOption *option;
+ g_return_val_if_fail (name != NULL, NULL);
+ g_return_val_if_fail (label != NULL, NULL);
+
option = g_object_new (ALSA_TYPE_SWITCH_OPTION,
"name", name,
"label", label,
diff --git a/backends/alsa/alsa-toggle.c b/backends/alsa/alsa-toggle.c
index 1fee1c1..d143236 100644
--- a/backends/alsa/alsa-toggle.c
+++ b/backends/alsa/alsa-toggle.c
@@ -89,6 +89,12 @@ alsa_toggle_new (AlsaStream *stream,
{
AlsaToggle *toggle;
+ g_return_val_if_fail (ALSA_IS_STREAM (stream), NULL);
+ g_return_val_if_fail (name != NULL, NULL);
+ g_return_val_if_fail (label != NULL, NULL);
+ g_return_val_if_fail (ALSA_IS_SWITCH_OPTION (on), NULL);
+ g_return_val_if_fail (ALSA_IS_SWITCH_OPTION (off), NULL);
+
toggle = g_object_new (ALSA_TYPE_TOGGLE,
"name", name,
"label", label,
@@ -166,6 +172,8 @@ alsa_toggle_load (AlsaElement *element)
gint ret;
snd_mixer_selem_channel_id_t c;
+ g_return_val_if_fail (ALSA_IS_TOGGLE (element), FALSE);
+
toggle = ALSA_TOGGLE (element);
if G_UNLIKELY (toggle->priv->element == NULL)
diff --git a/backends/oss/oss-backend.c b/backends/oss/oss-backend.c
index 70b32be..9726570 100644
--- a/backends/oss/oss-backend.c
+++ b/backends/oss/oss-backend.c
@@ -298,7 +298,7 @@ read_devices (OssBackend *oss)
for (i = 0; i < OSS_MAX_DEVICES; i++) {
gchar *path;
- gboolean added_current = FALSE;
+ gboolean added_current;
path = g_strdup_printf ("/dev/mixer%i", i);
@@ -333,6 +333,8 @@ read_device (OssBackend *oss, const gchar *path, gboolean *added)
gchar *bname;
gchar *label;
+ *added = FALSE;
+
fd = g_open (path, O_RDWR, 0);
if (fd == -1) {
if (errno != ENOENT && errno != ENXIO)
@@ -360,11 +362,13 @@ read_device (OssBackend *oss, const gchar *path, gboolean *added)
close (fd);
- if ((*added = oss_device_open (device)) == TRUE)
- add_device (oss, device);
- else
- g_object_unref (device);
-
+ if G_LIKELY (device != NULL) {
+ *added = oss_device_open (device);
+ if (*added == TRUE)
+ add_device (oss, device);
+ else
+ g_object_unref (device);
+ }
return *added;
}
diff --git a/backends/oss/oss-device.c b/backends/oss/oss-device.c
index e89e6e8..70f46e6 100644
--- a/backends/oss/oss-device.c
+++ b/backends/oss/oss-device.c
@@ -274,18 +274,26 @@ oss_device_new (const gchar *name,
gint fd)
{
OssDevice *device;
+ gint newfd;
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (label != NULL, NULL);
g_return_val_if_fail (path != NULL, NULL);
+ newfd = dup (fd);
+ if (newfd == -1) {
+ g_warning ("Failed to duplicate file descriptor: %s",
+ g_strerror (errno));
+ return NULL;
+ }
+
device = g_object_new (OSS_TYPE_DEVICE,
"name", name,
"label", label,
"icon", OSS_DEVICE_ICON,
NULL);
- device->priv->fd = dup (fd);
+ device->priv->fd = newfd;
device->priv->path = g_strdup (path);
return device;
@@ -584,6 +592,8 @@ read_mixer_devices (OssDevice *device)
device->priv->fd,
i,
stereo);
+ if G_UNLIKELY (control == NULL)
+ continue;
if (oss_stream_has_controls (stream) == FALSE) {
const gchar *name =
diff --git a/backends/oss/oss-stream-control.c b/backends/oss/oss-stream-control.c
index 0307fc7..9bdd3a5 100644
--- a/backends/oss/oss-stream-control.c
+++ b/backends/oss/oss-stream-control.c
@@ -24,6 +24,7 @@
#include <libmatemixer/matemixer-private.h>
#include "oss-common.h"
+#include "oss-stream.h"
#include "oss-stream-control.h"
#define OSS_VOLUME_JOIN(left,right) (((left) & 0xFF) | (((right) & 0xFF) << 8))
@@ -136,10 +137,19 @@ oss_stream_control_new (const gchar *name,
gboolean stereo)
{
OssStreamControl *control;
+ gint newfd;
MateMixerStreamControlFlags flags;
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (label != NULL, NULL);
+ g_return_val_if_fail (OSS_IS_STREAM (stream), NULL);
+
+ newfd = dup (fd);
+ if (newfd == -1) {
+ g_warning ("Failed to duplicate file descriptor: %s",
+ g_strerror (errno));
+ return NULL;
+ }
flags = MATE_MIXER_STREAM_CONTROL_VOLUME_READABLE |
MATE_MIXER_STREAM_CONTROL_VOLUME_WRITABLE;
@@ -154,7 +164,7 @@ oss_stream_control_new (const gchar *name,
"stream", stream,
NULL);
- control->priv->fd = fd;
+ control->priv->fd = newfd;
control->priv->devnum = devnum;
control->priv->stereo = stereo;
return control;
@@ -367,18 +377,24 @@ oss_stream_control_get_min_volume (MateMixerStreamControl *mmsc)
static guint
oss_stream_control_get_max_volume (MateMixerStreamControl *mmsc)
{
+ g_return_val_if_fail (OSS_IS_STREAM_CONTROL (mmsc), 0);
+
return 100;
}
static guint
oss_stream_control_get_normal_volume (MateMixerStreamControl *mmsc)
{
+ g_return_val_if_fail (OSS_IS_STREAM_CONTROL (mmsc), 0);
+
return 100;
}
static guint
oss_stream_control_get_base_volume (MateMixerStreamControl *mmsc)
{
+ g_return_val_if_fail (OSS_IS_STREAM_CONTROL (mmsc), 0);
+
return 100;
}
diff --git a/backends/oss/oss-stream.c b/backends/oss/oss-stream.c
index 0e7a0c0..f094537 100644
--- a/backends/oss/oss-stream.c
+++ b/backends/oss/oss-stream.c
@@ -21,6 +21,7 @@
#include <libmatemixer/matemixer.h>
#include <libmatemixer/matemixer-private.h>
+#include "oss-device.h"
#include "oss-stream.h"
#include "oss-stream-control.h"
#include "oss-switch.h"
@@ -93,7 +94,12 @@ oss_stream_new (const gchar *name,
MateMixerDevice *device,
MateMixerDirection direction)
{
- const gchar *label = mate_mixer_device_get_label (device);
+ const gchar *label;
+
+ g_return_val_if_fail (name != NULL, NULL);
+ g_return_val_if_fail (OSS_IS_DEVICE (device), NULL);
+
+ label = mate_mixer_device_get_label (device);
return g_object_new (OSS_TYPE_STREAM,
"name", name,
@@ -208,6 +214,8 @@ oss_stream_set_switch_data (OssStream *stream, gint fd, GList *options)
_("Connector"),
fd,
options);
+ if G_UNLIKELY (stream->priv->swtch == NULL)
+ return;
/* Read the active selection */
oss_switch_load (stream->priv->swtch);
diff --git a/backends/oss/oss-switch-option.c b/backends/oss/oss-switch-option.c
index 862133d..544f321 100644
--- a/backends/oss/oss-switch-option.c
+++ b/backends/oss/oss-switch-option.c
@@ -53,6 +53,9 @@ oss_switch_option_new (const gchar *name,
{
OssSwitchOption *option;
+ g_return_val_if_fail (name != NULL, NULL);
+ g_return_val_if_fail (label != NULL, NULL);
+
option = g_object_new (OSS_TYPE_SWITCH_OPTION,
"name", name,
"label", label,
diff --git a/backends/oss/oss-switch.c b/backends/oss/oss-switch.c
index 6b78833..ba07d36 100644
--- a/backends/oss/oss-switch.c
+++ b/backends/oss/oss-switch.c
@@ -107,13 +107,20 @@ oss_switch_new (OssStream *stream,
GList *options)
{
OssSwitch *swtch;
+ gint newfd;
g_return_val_if_fail (OSS_IS_STREAM (stream), NULL);
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (label != NULL, NULL);
- g_return_val_if_fail (fd != -1, NULL);
g_return_val_if_fail (options != NULL, NULL);
+ newfd = dup (fd);
+ if (newfd == -1) {
+ g_warning ("Failed to duplicate file descriptor: %s",
+ g_strerror (errno));
+ return NULL;
+ }
+
swtch = g_object_new (OSS_TYPE_SWITCH,
"name", name,
"label", label,
@@ -122,7 +129,7 @@ oss_switch_new (OssStream *stream,
NULL);
/* Takes ownership of options */
- swtch->priv->fd = dup (fd);
+ swtch->priv->fd = newfd;
swtch->priv->options = options;
return swtch;
diff --git a/backends/pulse/pulse-connection.c b/backends/pulse/pulse-connection.c
index 995b522..62156c1 100644
--- a/backends/pulse/pulse-connection.c
+++ b/backends/pulse/pulse-connection.c
@@ -786,6 +786,7 @@ pulse_connection_set_default_sink (PulseConnection *connection,
pa_operation *op;
g_return_val_if_fail (PULSE_IS_CONNECTION (connection), FALSE);
+ g_return_val_if_fail (name != NULL, FALSE);
if (connection->priv->state != PULSE_CONNECTION_CONNECTED)
return FALSE;
@@ -804,6 +805,7 @@ pulse_connection_set_default_source (PulseConnection *connection,
pa_operation *op;
g_return_val_if_fail (PULSE_IS_CONNECTION (connection), FALSE);
+ g_return_val_if_fail (name != NULL, FALSE);
if (connection->priv->state != PULSE_CONNECTION_CONNECTED)
return FALSE;
@@ -823,6 +825,8 @@ pulse_connection_set_card_profile (PulseConnection *connection,
pa_operation *op;
g_return_val_if_fail (PULSE_IS_CONNECTION (connection), FALSE);
+ g_return_val_if_fail (card != NULL, FALSE);
+ g_return_val_if_fail (profile != NULL, FALSE);
if (connection->priv->state != PULSE_CONNECTION_CONNECTED)
return FALSE;
@@ -863,6 +867,7 @@ pulse_connection_set_sink_volume (PulseConnection *connection,
pa_operation *op;
g_return_val_if_fail (PULSE_IS_CONNECTION (connection), FALSE);
+ g_return_val_if_fail (volume != NULL, FALSE);
if (connection->priv->state != PULSE_CONNECTION_CONNECTED)
return FALSE;
@@ -883,6 +888,7 @@ pulse_connection_set_sink_port (PulseConnection *connection,
pa_operation *op;
g_return_val_if_fail (PULSE_IS_CONNECTION (connection), FALSE);
+ g_return_val_if_fail (port != NULL, FALSE);
if (connection->priv->state != PULSE_CONNECTION_CONNECTED)
return FALSE;
@@ -923,6 +929,7 @@ pulse_connection_set_sink_input_volume (PulseConnection *connection,
pa_operation *op;
g_return_val_if_fail (PULSE_IS_CONNECTION (connection), FALSE);
+ g_return_val_if_fail (volume != NULL, FALSE);
if (connection->priv->state != PULSE_CONNECTION_CONNECTED)
return FALSE;
@@ -963,6 +970,7 @@ pulse_connection_set_source_volume (PulseConnection *connection,
pa_operation *op;
g_return_val_if_fail (PULSE_IS_CONNECTION (connection), FALSE);
+ g_return_val_if_fail (volume != NULL, FALSE);
if (connection->priv->state != PULSE_CONNECTION_CONNECTED)
return FALSE;
@@ -983,6 +991,7 @@ pulse_connection_set_source_port (PulseConnection *connection,
pa_operation *op;
g_return_val_if_fail (PULSE_IS_CONNECTION (connection), FALSE);
+ g_return_val_if_fail (port != NULL, FALSE);
if (connection->priv->state != PULSE_CONNECTION_CONNECTED)
return FALSE;
@@ -1023,6 +1032,7 @@ pulse_connection_set_source_output_volume (PulseConnection *connection,
pa_operation *op;
g_return_val_if_fail (PULSE_IS_CONNECTION (connection), FALSE);
+ g_return_val_if_fail (volume != NULL, FALSE);
if (connection->priv->state != PULSE_CONNECTION_CONNECTED)
return FALSE;
@@ -1158,6 +1168,7 @@ pulse_connection_write_ext_stream (PulseConnection *connection,
pa_operation *op;
g_return_val_if_fail (PULSE_IS_CONNECTION (connection), FALSE);
+ g_return_val_if_fail (info != NULL, FALSE);
if (connection->priv->state != PULSE_CONNECTION_CONNECTED)
return FALSE;
@@ -1179,6 +1190,7 @@ pulse_connection_delete_ext_stream (PulseConnection *connection,
gchar **names;
g_return_val_if_fail (PULSE_IS_CONNECTION (connection), FALSE);
+ g_return_val_if_fail (name != NULL, FALSE);
if (connection->priv->state != PULSE_CONNECTION_CONNECTED)
return FALSE;
diff --git a/backends/pulse/pulse-device-switch.c b/backends/pulse/pulse-device-switch.c
index c6b8316..4bd32ce 100644
--- a/backends/pulse/pulse-device-switch.c
+++ b/backends/pulse/pulse-device-switch.c
@@ -89,6 +89,10 @@ pulse_device_switch_dispose (GObject *object)
PulseDeviceSwitch *
pulse_device_switch_new (const gchar *name, const gchar *label, PulseDevice *device)
{
+ g_return_val_if_fail (name != NULL, NULL);
+ g_return_val_if_fail (label != NULL, NULL);
+ g_return_val_if_fail (PULSE_IS_DEVICE (device), NULL);
+
return g_object_new (PULSE_TYPE_DEVICE_SWITCH,
"name", name,
"label", label,
diff --git a/backends/pulse/pulse-device.c b/backends/pulse/pulse-device.c
index d53c86a..9b75ca4 100644
--- a/backends/pulse/pulse-device.c
+++ b/backends/pulse/pulse-device.c
@@ -330,6 +330,7 @@ PulsePort *
pulse_device_get_port (PulseDevice *device, const gchar *name)
{
g_return_val_if_fail (PULSE_IS_DEVICE (device), NULL);
+ g_return_val_if_fail (name != NULL, NULL);
return g_hash_table_lookup (device->priv->ports, name);
}
diff --git a/backends/pulse/pulse-ext-stream.c b/backends/pulse/pulse-ext-stream.c
index 2ebf8e7..e99fbb1 100644
--- a/backends/pulse/pulse-ext-stream.c
+++ b/backends/pulse/pulse-ext-stream.c
@@ -393,8 +393,12 @@ pulse_ext_stream_update (PulseExtStream *ext,
_mate_mixer_stream_control_set_flags (MATE_MIXER_STREAM_CONTROL (ext), flags);
/* Also set initially, but may change at any time */
- _mate_mixer_stream_control_set_stream (MATE_MIXER_STREAM_CONTROL (ext),
- MATE_MIXER_STREAM (parent));
+ if (parent != NULL)
+ _mate_mixer_stream_control_set_stream (MATE_MIXER_STREAM_CONTROL (ext),
+ MATE_MIXER_STREAM (parent));
+ else
+ _mate_mixer_stream_control_set_stream (MATE_MIXER_STREAM_CONTROL (ext),
+ NULL);
g_object_thaw_notify (G_OBJECT (ext));
}
diff --git a/backends/pulse/pulse-helpers.c b/backends/pulse/pulse-helpers.c
index 671c3e2..f1272ae 100644
--- a/backends/pulse/pulse-helpers.c
+++ b/backends/pulse/pulse-helpers.c
@@ -73,6 +73,8 @@ const pa_channel_position_t pulse_channel_map_to[MATE_MIXER_CHANNEL_MAX] =
MateMixerStreamControlMediaRole
pulse_convert_media_role_name (const gchar *name)
{
+ g_return_val_if_fail (name != NULL, MATE_MIXER_STREAM_CONTROL_MEDIA_ROLE_UNKNOWN);
+
if (!strcmp (name, "video")) {
return MATE_MIXER_STREAM_CONTROL_MEDIA_ROLE_VIDEO;
}
diff --git a/backends/pulse/pulse-sink-input.c b/backends/pulse/pulse-sink-input.c
index eb812c6..c20a820 100644
--- a/backends/pulse/pulse-sink-input.c
+++ b/backends/pulse/pulse-sink-input.c
@@ -146,8 +146,12 @@ pulse_sink_input_new (PulseSink *sink, const pa_sink_input_info *info)
NULL);
g_free (name);
- if (app_info != NULL)
- pulse_stream_control_set_app_info (PULSE_STREAM_CONTROL (input), app_info);
+ if (app_info != NULL) {
+ /* Takes ownership of app_info */
+ pulse_stream_control_set_app_info (PULSE_STREAM_CONTROL (input),
+ app_info,
+ TRUE);
+ }
pulse_sink_input_update (input, info);
return input;
diff --git a/backends/pulse/pulse-sink-switch.c b/backends/pulse/pulse-sink-switch.c
index 62aca94..74c182f 100644
--- a/backends/pulse/pulse-sink-switch.c
+++ b/backends/pulse/pulse-sink-switch.c
@@ -24,6 +24,7 @@
#include "pulse-connection.h"
#include "pulse-port.h"
#include "pulse-port-switch.h"
+#include "pulse-sink.h"
#include "pulse-sink-switch.h"
#include "pulse-stream.h"
@@ -52,6 +53,10 @@ pulse_sink_switch_init (PulseSinkSwitch *swtch)
PulsePortSwitch *
pulse_sink_switch_new (const gchar *name, const gchar *label, PulseSink *sink)
{
+ g_return_val_if_fail (name != NULL, NULL);
+ g_return_val_if_fail (label != NULL, NULL);
+ g_return_val_if_fail (PULSE_IS_SINK (sink), NULL);
+
return g_object_new (PULSE_TYPE_SINK_SWITCH,
"name", name,
"label", label,
diff --git a/backends/pulse/pulse-sink.c b/backends/pulse/pulse-sink.c
index 294643c..616331b 100644
--- a/backends/pulse/pulse-sink.c
+++ b/backends/pulse/pulse-sink.c
@@ -130,6 +130,7 @@ pulse_sink_new (PulseConnection *connection,
g_return_val_if_fail (PULSE_IS_CONNECTION (connection), NULL);
g_return_val_if_fail (info != NULL, NULL);
+ g_return_val_if_fail (device == NULL || PULSE_IS_DEVICE (device), NULL);
sink = g_object_new (PULSE_TYPE_SINK,
"name", info->name,
@@ -189,6 +190,9 @@ pulse_sink_add_input (PulseSink *sink, const pa_sink_input_info *info)
{
PulseSinkInput *input;
+ g_return_val_if_fail (PULSE_IS_SINK (sink), FALSE);
+ g_return_val_if_fail (info != NULL, FALSE);
+
/* This function is used for both creating and refreshing sink inputs */
input = g_hash_table_lookup (sink->priv->inputs, GUINT_TO_POINTER (info->index));
if (input == NULL) {
@@ -218,6 +222,8 @@ pulse_sink_remove_input (PulseSink *sink, guint32 index)
PulseSinkInput *input;
gchar *name;
+ g_return_if_fail (PULSE_IS_SINK (sink));
+
input = g_hash_table_lookup (sink->priv->inputs, GUINT_TO_POINTER (index));
if G_UNLIKELY (input == NULL)
return;
diff --git a/backends/pulse/pulse-source-output.c b/backends/pulse/pulse-source-output.c
index a48f9f6..9a38250 100644
--- a/backends/pulse/pulse-source-output.c
+++ b/backends/pulse/pulse-source-output.c
@@ -134,8 +134,12 @@ pulse_source_output_new (PulseSource *source,
NULL);
g_free (name);
- if (app_info != NULL)
- pulse_stream_control_set_app_info (PULSE_STREAM_CONTROL (output), app_info);
+ if (app_info != NULL) {
+ /* Takes ownership of app_info */
+ pulse_stream_control_set_app_info (PULSE_STREAM_CONTROL (output),
+ app_info,
+ TRUE);
+ }
pulse_source_output_update (output, info);
return output;
diff --git a/backends/pulse/pulse-source-switch.c b/backends/pulse/pulse-source-switch.c
index 9616bb1..76f97f0 100644
--- a/backends/pulse/pulse-source-switch.c
+++ b/backends/pulse/pulse-source-switch.c
@@ -24,6 +24,7 @@
#include "pulse-connection.h"
#include "pulse-port.h"
#include "pulse-port-switch.h"
+#include "pulse-source.h"
#include "pulse-source-switch.h"
#include "pulse-stream.h"
@@ -52,6 +53,10 @@ pulse_source_switch_init (PulseSourceSwitch *swtch)
PulsePortSwitch *
pulse_source_switch_new (const gchar *name, const gchar *label, PulseSource *source)
{
+ g_return_val_if_fail (name != NULL, NULL);
+ g_return_val_if_fail (label != NULL, NULL);
+ g_return_val_if_fail (PULSE_IS_SOURCE (source), NULL);
+
return g_object_new (PULSE_TYPE_SOURCE_SWITCH,
"name", name,
"label", label,
diff --git a/backends/pulse/pulse-source.c b/backends/pulse/pulse-source.c
index acba188..570423d 100644
--- a/backends/pulse/pulse-source.c
+++ b/backends/pulse/pulse-source.c
@@ -127,6 +127,7 @@ pulse_source_new (PulseConnection *connection,
g_return_val_if_fail (PULSE_IS_CONNECTION (connection), NULL);
g_return_val_if_fail (info != NULL, NULL);
+ g_return_val_if_fail (device == NULL || PULSE_IS_DEVICE (device), NULL);
source = g_object_new (PULSE_TYPE_SOURCE,
"name", info->name,
@@ -186,6 +187,9 @@ pulse_source_add_output (PulseSource *source, const pa_source_output_info *info)
{
PulseSourceOutput *output;
+ g_return_val_if_fail (PULSE_IS_SOURCE (source), FALSE);
+ g_return_val_if_fail (info != NULL, FALSE);
+
/* This function is used for both creating and refreshing source outputs */
output = g_hash_table_lookup (source->priv->outputs, GUINT_TO_POINTER (info->index));
if (output == NULL) {
@@ -215,6 +219,8 @@ pulse_source_remove_output (PulseSource *source, guint32 index)
PulseSourceOutput *output;
gchar *name;
+ g_return_if_fail (PULSE_IS_SOURCE (source));
+
output = g_hash_table_lookup (source->priv->outputs, GUINT_TO_POINTER (index));
if G_UNLIKELY (output == NULL)
return;
diff --git a/backends/pulse/pulse-stream-control.c b/backends/pulse/pulse-stream-control.c
index bc59c97..fe4304c 100644
--- a/backends/pulse/pulse-stream-control.c
+++ b/backends/pulse/pulse-stream-control.c
@@ -308,14 +308,19 @@ pulse_stream_control_get_channel_map (PulseStreamControl *control)
}
void
-pulse_stream_control_set_app_info (PulseStreamControl *control, MateMixerAppInfo *info)
+pulse_stream_control_set_app_info (PulseStreamControl *control,
+ MateMixerAppInfo *info,
+ gboolean take)
{
g_return_if_fail (PULSE_IS_STREAM_CONTROL (control));
- if G_UNLIKELY (control->priv->app_info)
+ if G_UNLIKELY (control->priv->app_info != NULL)
_mate_mixer_app_info_free (control->priv->app_info);
- control->priv->app_info = info;
+ if (take == TRUE)
+ control->priv->app_info = info;
+ else
+ control->priv->app_info = _mate_mixer_app_info_copy (info);
}
void
@@ -324,11 +329,10 @@ pulse_stream_control_set_channel_map (PulseStreamControl *control, const pa_chan
MateMixerStreamControlFlags flags;
g_return_if_fail (PULSE_IS_STREAM_CONTROL (control));
- g_return_if_fail (map != NULL);
flags = mate_mixer_stream_control_get_flags (MATE_MIXER_STREAM_CONTROL (control));
- if (pa_channel_map_valid (map)) {
+ if (map != NULL && pa_channel_map_valid (map)) {
if (pa_channel_map_can_balance (map))
flags |= MATE_MIXER_STREAM_CONTROL_CAN_BALANCE;
else
diff --git a/backends/pulse/pulse-stream-control.h b/backends/pulse/pulse-stream-control.h
index abc3f98..c37d6eb 100644
--- a/backends/pulse/pulse-stream-control.h
+++ b/backends/pulse/pulse-stream-control.h
@@ -81,7 +81,8 @@ const pa_cvolume * pulse_stream_control_get_cvolume (PulseStreamControl
const pa_channel_map *pulse_stream_control_get_channel_map (PulseStreamControl *control);
void pulse_stream_control_set_app_info (PulseStreamControl *stream,
- MateMixerAppInfo *info);
+ MateMixerAppInfo *info,
+ gboolean take);
void pulse_stream_control_set_channel_map (PulseStreamControl *control,
const pa_channel_map *map);
diff --git a/libmatemixer/matemixer-backend.c b/libmatemixer/matemixer-backend.c
index 56efd94..682bf68 100644
--- a/libmatemixer/matemixer-backend.c
+++ b/libmatemixer/matemixer-backend.c
@@ -618,6 +618,7 @@ _mate_mixer_backend_set_default_input_stream (MateMixerBackend *backend,
MateMixerStream *stream)
{
g_return_if_fail (MATE_MIXER_IS_BACKEND (backend));
+ g_return_if_fail (stream == NULL || MATE_MIXER_IS_STREAM (stream));
if (backend->priv->default_input == stream)
return;
@@ -642,6 +643,7 @@ _mate_mixer_backend_set_default_output_stream (MateMixerBackend *backend,
MateMixerStream *stream)
{
g_return_if_fail (MATE_MIXER_IS_BACKEND (backend));
+ g_return_if_fail (stream == NULL || MATE_MIXER_IS_STREAM (stream));
if (backend->priv->default_output == stream)
return;
diff --git a/libmatemixer/matemixer-device.c b/libmatemixer/matemixer-device.c
index cda9657..7cf417b 100644
--- a/libmatemixer/matemixer-device.c
+++ b/libmatemixer/matemixer-device.c
@@ -382,6 +382,9 @@ mate_mixer_device_get_icon (MateMixerDevice *device)
MateMixerStream *
mate_mixer_device_get_stream (MateMixerDevice *device, const gchar *name)
{
+ g_return_val_if_fail (MATE_MIXER_IS_DEVICE (device), NULL);
+ g_return_val_if_fail (name != NULL, NULL);
+
return MATE_MIXER_DEVICE_GET_CLASS (device)->get_stream (device, name);
}
@@ -404,6 +407,9 @@ mate_mixer_device_get_stream (MateMixerDevice *device, const gchar *name)
MateMixerDeviceSwitch *
mate_mixer_device_get_switch (MateMixerDevice *device, const gchar *name)
{
+ g_return_val_if_fail (MATE_MIXER_IS_DEVICE (device), NULL);
+ g_return_val_if_fail (name != NULL, NULL);
+
return MATE_MIXER_DEVICE_GET_CLASS (device)->get_switch (device, name);
}
diff --git a/libmatemixer/matemixer-stream-control.c b/libmatemixer/matemixer-stream-control.c
index 5d97709..98286b1 100644
--- a/libmatemixer/matemixer-stream-control.c
+++ b/libmatemixer/matemixer-stream-control.c
@@ -405,6 +405,7 @@ mate_mixer_stream_control_set_stream (MateMixerStreamControl *control,
MateMixerStream *stream)
{
g_return_val_if_fail (MATE_MIXER_IS_STREAM_CONTROL (control), FALSE);
+ g_return_val_if_fail (stream == NULL || MATE_MIXER_IS_STREAM (stream), FALSE);
if ((control->priv->flags & MATE_MIXER_STREAM_CONTROL_MOVABLE) == 0)
return FALSE;
@@ -882,6 +883,7 @@ _mate_mixer_stream_control_set_stream (MateMixerStreamControl *control,
MateMixerStream *stream)
{
g_return_if_fail (MATE_MIXER_IS_STREAM_CONTROL (control));
+ g_return_if_fail (stream == NULL || MATE_MIXER_IS_STREAM (stream));
if (control->priv->stream == stream)
return;
diff --git a/libmatemixer/matemixer-switch.c b/libmatemixer/matemixer-switch.c
index b61f13a..8fc0a3f 100644
--- a/libmatemixer/matemixer-switch.c
+++ b/libmatemixer/matemixer-switch.c
@@ -253,6 +253,7 @@ MateMixerSwitchOption *
mate_mixer_switch_get_option (MateMixerSwitch *swtch, const gchar *name)
{
g_return_val_if_fail (MATE_MIXER_IS_SWITCH (swtch), NULL);
+ g_return_val_if_fail (name != NULL, NULL);
return MATE_MIXER_SWITCH_GET_CLASS (swtch)->get_option (swtch, name);
}