From 23802b4fe0cf5821b72aa5bc682e38c8c91bb168 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Mon, 10 Feb 2014 09:28:02 +0800 Subject: qtest: Don't segfault with invalid -qtest option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This prints an error message, instead of core dump, when "-qtest" option value is invalid, e.g.: $ ./x86_64-softmmu/qemu-system-x86_64 -qtest unknown qemu-system-x86_64: Failed to initialize device for qtest: "unknown" Signed-off-by: Fam Zheng Signed-off-by: Andreas Färber --- qtest.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'qtest.c') diff --git a/qtest.c b/qtest.c index a738afc724..ae941d6551 100644 --- a/qtest.c +++ b/qtest.c @@ -507,12 +507,18 @@ int qtest_init_accel(void) return 0; } -void qtest_init(const char *qtest_chrdev, const char *qtest_log) +void qtest_init(const char *qtest_chrdev, const char *qtest_log, Error **errp) { CharDriverState *chr; chr = qemu_chr_new("qtest", qtest_chrdev, NULL); + if (chr == NULL) { + error_setg(errp, "Failed to initialize device for qtest: \"%s\"", + qtest_chrdev); + return; + } + qemu_chr_add_handlers(chr, qtest_can_read, qtest_read, qtest_event, chr); qemu_chr_fe_set_echo(chr, true); -- cgit v1.2.1