From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>, Frediano Ziglio <fziglio@redhat.com>
Subject: [Qemu-devel] [PULL 1/5] audio: Use g_strdup_printf instead of manual building a string
Date: Thu, 28 Feb 2019 11:08:54 +0100 [thread overview]
Message-ID: <20190228100858.28397-2-kraxel@redhat.com> (raw)
In-Reply-To: <20190228100858.28397-1-kraxel@redhat.com>
From: Frediano Ziglio <fziglio@redhat.com>
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>
---
audio/audio.c | 25 +++++--------------------
1 file changed, 5 insertions(+), 20 deletions(-)
diff --git a/audio/audio.c b/audio/audio.c
index d163ffbc88f4..472721a7a9f0 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)
--
2.9.3
next prev parent reply other threads:[~2019-02-28 10:09 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-28 10:08 [Qemu-devel] [PULL 0/5] Audio 20190228 patches Gerd Hoffmann
2019-02-28 10:08 ` Gerd Hoffmann [this message]
2019-02-28 10:08 ` [Qemu-devel] [PULL 2/5] audio: Do not check for audio_calloc failure Gerd Hoffmann
2019-02-28 10:08 ` [Qemu-devel] [PULL 3/5] audio: don't build alsa and sdl by default on linux Gerd Hoffmann
2019-02-28 10:08 ` [Qemu-devel] [PULL 4/5] audio/sdlaudio: Remove the semaphore code Gerd Hoffmann
2019-02-28 10:08 ` [Qemu-devel] [PULL 5/5] audio/sdlaudio: Simplify the sdl_callback function Gerd Hoffmann
2019-02-28 17:35 ` [Qemu-devel] [PULL 0/5] Audio 20190228 patches Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190228100858.28397-2-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=fziglio@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).