summaryrefslogtreecommitdiff
path: root/backends/oss
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 /backends/oss
parentd32ca3f420d036cd750fc1aad7f95da40559cc5d (diff)
downloadlibmatemixer-9772797c31ebed2417b42a9389caae1b16847e86.tar.bz2
libmatemixer-9772797c31ebed2417b42a9389caae1b16847e86.tar.xz
Improve error checking in many places
Diffstat (limited to 'backends/oss')
-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
6 files changed, 59 insertions, 11 deletions
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;