aboutsummaryrefslogtreecommitdiffstats
path: root/src/volume.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-07-06 21:52:10 +0200
committerMax Kellermann <max@duempel.org>2009-07-06 21:52:10 +0200
commitd3b5574d7aac0a7f2d4eb785facfad9f37c15dd5 (patch)
tree9255929810567b241a34b7c2c77479c49271b99a /src/volume.c
parent90472526e00c671f76d78341b5e474fcf069d41e (diff)
downloadmpd-d3b5574d7aac0a7f2d4eb785facfad9f37c15dd5.tar.gz
mpd-d3b5574d7aac0a7f2d4eb785facfad9f37c15dd5.tar.xz
mpd-d3b5574d7aac0a7f2d4eb785facfad9f37c15dd5.zip
volume: moved range check to handle_setvol()
Converted the range checks in volume_level_change() to assertions. Changed all volume types to "unsigned", expect for those which must be able to indicate error (-1).
Diffstat (limited to 'src/volume.c')
-rw-r--r--src/volume.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/volume.c b/src/volume.c
index 146c6b13a..3d240f4e4 100644
--- a/src/volume.c
+++ b/src/volume.c
@@ -42,7 +42,7 @@
static enum mixer_type volume_mixer_type = MIXER_TYPE_HARDWARE;
-static int volume_software_set = 100;
+static unsigned volume_software_set = 100;
/** the cached hardware mixer value; invalid if negative */
static int last_hardware_volume = -1;
@@ -117,12 +117,9 @@ int volume_level_get(void)
return -1;
}
-static bool software_volume_change(int volume)
+static bool software_volume_change(unsigned volume)
{
- if (volume > 100)
- volume = 100;
- else if (volume < 0)
- volume = 0;
+ assert(volume <= 100);
volume_software_set = volume;
@@ -139,7 +136,7 @@ static bool software_volume_change(int volume)
return true;
}
-static bool hardware_volume_change(int volume)
+static bool hardware_volume_change(unsigned volume)
{
/* reset the cache */
last_hardware_volume = -1;
@@ -147,8 +144,10 @@ static bool hardware_volume_change(int volume)
return mixer_all_set_volume(volume);
}
-bool volume_level_change(int volume)
+bool volume_level_change(unsigned volume)
{
+ assert(volume <= 100);
+
idle_add(IDLE_MIXER);
switch (volume_mixer_type) {
@@ -175,7 +174,7 @@ void read_sw_volume_state(FILE *fp)
g_strchomp(buf);
sv = strtol(buf + strlen(SW_VOLUME_STATE), &end, 10);
- if (G_LIKELY(!*end))
+ if (G_LIKELY(!*end) && sv >= 0 && sv <= 100)
software_volume_change(sv);
else
g_warning("Can't parse software volume: %s\n", buf);
@@ -186,5 +185,5 @@ void read_sw_volume_state(FILE *fp)
void save_sw_volume_state(FILE *fp)
{
if (volume_mixer_type == MIXER_TYPE_SOFTWARE)
- fprintf(fp, SW_VOLUME_STATE "%d\n", volume_software_set);
+ fprintf(fp, SW_VOLUME_STATE "%u\n", volume_software_set);
}