aboutsummaryrefslogtreecommitdiff
path: root/audio
diff options
context:
space:
mode:
authorFrediano Ziglio <fziglio@redhat.com>2019-02-25 15:43:34 +0000
committerGerd Hoffmann <kraxel@redhat.com>2019-02-28 10:26:53 +0100
commit71f2874fc10cfd0c0dbbe560d250d0cafa9fe220 (patch)
tree519f9acf444baacf05a398644f58c17df6c08a4c /audio
parent86c7e2f4a93322a76afea5ee6806a83420d1dfea (diff)
audio: Use g_strdup_printf instead of manual building a string
Instead of using lot of low level function and manually allocate the temporary string in audio_process_options use more high level GLib function. The function is not used in hot path but to read some initial setting. Signed-off-by: Frediano Ziglio <fziglio@redhat.com> Message-id: 20190225154335.11397-1-fziglio@redhat.com Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'audio')
-rw-r--r--audio/audio.c25
1 files changed, 5 insertions, 20 deletions
diff --git a/audio/audio.c b/audio/audio.c
index d163ffbc88..472721a7a9 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -454,9 +454,7 @@ static void audio_print_options (const char *prefix,
static void audio_process_options (const char *prefix,
struct audio_option *opt)
{
- char *optname;
- const char qemu_prefix[] = "QEMU_";
- size_t preflen, optlen;
+ gchar *prefix_upper;
if (audio_bug(__func__, !prefix)) {
dolog ("prefix = NULL\n");
@@ -468,10 +466,10 @@ static void audio_process_options (const char *prefix,
return;
}
- preflen = strlen (prefix);
+ prefix_upper = g_utf8_strup(prefix, -1);
for (; opt->name; opt++) {
- size_t len, i;
+ char *optname;
int def;
if (!opt->valp) {
@@ -480,21 +478,7 @@ static void audio_process_options (const char *prefix,
continue;
}
- len = strlen (opt->name);
- /* len of opt->name + len of prefix + size of qemu_prefix
- * (includes trailing zero) + zero + underscore (on behalf of
- * sizeof) */
- optlen = len + preflen + sizeof (qemu_prefix) + 1;
- optname = g_malloc (optlen);
-
- pstrcpy (optname, optlen, qemu_prefix);
-
- /* copy while upper-casing, including trailing zero */
- for (i = 0; i <= preflen; ++i) {
- optname[i + sizeof (qemu_prefix) - 1] = qemu_toupper(prefix[i]);
- }
- pstrcat (optname, optlen, "_");
- pstrcat (optname, optlen, opt->name);
+ optname = g_strdup_printf("QEMU_%s_%s", prefix_upper, opt->name);
def = 1;
switch (opt->tag) {
@@ -532,6 +516,7 @@ static void audio_process_options (const char *prefix,
*opt->overriddenp = !def;
g_free (optname);
}
+ g_free(prefix_upper);
}
static void audio_print_settings (struct audsettings *as)