summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2010-03-22 16:13:12 +0100
committerBenjamin Otte <otte@redhat.com>2010-03-22 16:22:22 +0100
commit5038a886ab5503cc996efdd35cdf14384d07ae6a (patch)
treefa211ff82f734465d3e21f6278406bf7b8a26cd4
parent9738d70e280f839ab53bf9f5b4cf4cedb29ea0b9 (diff)
oss4: Refactor code to make it look more modern
A side effect is that it passes -Wformat-nonliteral and doesn't read invalid memory in some cases, like when the mixer track contains a % sign or there is a number but not a known mixer name.
-rw-r--r--sys/oss4/oss4-mixer.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/sys/oss4/oss4-mixer.c b/sys/oss4/oss4-mixer.c
index cabd6b73a..e8d80053d 100644
--- a/sys/oss4/oss4-mixer.c
+++ b/sys/oss4/oss4-mixer.c
@@ -854,14 +854,11 @@ static gchar *
gst_oss4_mixer_control_get_translated_name (GstOss4MixerControl * mc)
{
gchar name[128] = { 0, };
- gchar scratch[128] = { 0, };
- gchar fmtbuf[128] = { 0, };
gchar vmix_str[32] = { '\0', };
gchar *ptr;
int dummy, i;
int num = -1;
-
- g_strlcpy (fmtbuf, "%s", sizeof (fmtbuf));
+ gboolean function_suffix = FALSE;
/* main virtual mixer controls (we hide the stream volumes) */
if (sscanf (mc->mixext.extname, "vmix%d-%32c", &dummy, vmix_str) == 2) {
@@ -880,13 +877,12 @@ gst_oss4_mixer_control_get_translated_name (GstOss4MixerControl * mc)
(g_str_has_prefix (name, "jack."))) {
ptr = strchr (mc->mixext.extname, '.');
ptr++;
- g_strlcpy (scratch, ptr, sizeof (scratch));
- g_strlcpy (name, scratch, sizeof (name));
+ g_strlcpy (name, ptr, sizeof (name));
}
/* special handling for jack retasking suffixes */
if (g_str_has_suffix (name, ".function") || g_str_has_suffix (name, ".mode")) {
- g_strlcpy (fmtbuf, _("%s Function"), sizeof (fmtbuf));
+ function_suffix = TRUE;
ptr = strrchr (name, '.');
*ptr = 0;
}
@@ -900,10 +896,6 @@ gst_oss4_mixer_control_get_translated_name (GstOss4MixerControl * mc)
if ((i > 0) && (name[i] != '\0')) {
num = atoi (name + i);
name[i] = '\0';
- /* format appends a number to the base, but preserves any surrounding
- format */
- g_snprintf (scratch, sizeof (scratch), fmtbuf, _("%s %d"));
- g_strlcpy (fmtbuf, scratch, sizeof (fmtbuf));
}
/* look for a match, progressively skipping '.' delimited prefixes as we go */
@@ -913,16 +905,29 @@ gst_oss4_mixer_control_get_translated_name (GstOss4MixerControl * mc)
ptr++;
for (i = 0; i < G_N_ELEMENTS (labels); ++i) {
if (g_strcasecmp (ptr, labels[i].oss_name) == 0) {
- g_snprintf (name, sizeof (name), fmtbuf, _(labels[i].label), num);
- return g_strdup (name);
+ g_strlcpy (name, _(labels[i].label), sizeof (name));
+ goto append_suffixes;
}
}
} while ((ptr = strchr (ptr, '.')) != NULL);
/* failing that, just replace periods with spaces */
g_strdelimit (name, ".", ' ');
- g_snprintf (scratch, sizeof (scratch), fmtbuf, name);
- return g_strdup (scratch);
+
+append_suffixes:
+ if (num > -1) {
+ if (function_suffix) {
+ return g_strdup_printf (_("%s %d Function"), name, num);
+ } else {
+ return g_strdup_printf (_("%s %d"), name, num);
+ }
+ } else {
+ if (function_suffix) {
+ return g_strdup_printf (_("%s Function"), name);
+ } else {
+ return g_strdup (name);
+ }
+ }
}
static const gchar *