block: Simplify setting numeric options

Don't convert numbers to strings for use with qemu_opt_set(), simply
use qemu_opt_set_number() instead.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Markus Armbruster 2015-02-13 15:50:43 +01:00
parent dc523cd348
commit a8b18f8fd2
2 changed files with 7 additions and 10 deletions

View File

@ -180,7 +180,6 @@ QemuOpts *drive_add(BlockInterfaceType type, int index, const char *file,
const char *optstr) const char *optstr)
{ {
QemuOpts *opts; QemuOpts *opts;
char buf[32];
opts = drive_def(optstr); opts = drive_def(optstr);
if (!opts) { if (!opts) {
@ -190,8 +189,7 @@ QemuOpts *drive_add(BlockInterfaceType type, int index, const char *file,
qemu_opt_set(opts, "if", if_name[type], &error_abort); qemu_opt_set(opts, "if", if_name[type], &error_abort);
} }
if (index >= 0) { if (index >= 0) {
snprintf(buf, sizeof(buf), "%d", index); qemu_opt_set_number(opts, "index", index, &error_abort);
qemu_opt_set(opts, "index", buf, &error_abort);
} }
if (file) if (file)
qemu_opt_set(opts, "file", file, &error_abort); qemu_opt_set(opts, "file", file, &error_abort);

13
vl.c
View File

@ -2971,13 +2971,12 @@ int main(int argc, char **argv, char **envp)
exit(1); exit(1);
} }
if (hda_opts != NULL) { if (hda_opts != NULL) {
char num[16]; qemu_opt_set_number(hda_opts, "cyls", cyls,
snprintf(num, sizeof(num), "%d", cyls); &error_abort);
qemu_opt_set(hda_opts, "cyls", num, &error_abort); qemu_opt_set_number(hda_opts, "heads", heads,
snprintf(num, sizeof(num), "%d", heads); &error_abort);
qemu_opt_set(hda_opts, "heads", num, &error_abort); qemu_opt_set_number(hda_opts, "secs", secs,
snprintf(num, sizeof(num), "%d", secs); &error_abort);
qemu_opt_set(hda_opts, "secs", num, &error_abort);
if (translation == BIOS_ATA_TRANSLATION_LARGE) { if (translation == BIOS_ATA_TRANSLATION_LARGE) {
qemu_opt_set(hda_opts, "trans", "large", qemu_opt_set(hda_opts, "trans", "large",
&error_abort); &error_abort);