OSDN Git Service

console: Fix warning from clang (and potential crash)
authorStefan Weil <sw@weilnetz.de>
Fri, 17 Aug 2012 13:50:44 +0000 (15:50 +0200)
committerAnthony Liguori <aliguori@us.ibm.com>
Fri, 31 Aug 2012 15:05:22 +0000 (10:05 -0500)
ccc-analyzer reports this warning:

console.c:1090:29: warning: Dereference of null pointer
        if (active_console->cursor_timer) {
                            ^

Function console_select allows active_console to be NULL,
but would crash when accessing cursor_timer. Fix this.

Reviewed-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Stefan Weil <sw@weilnetz.de>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
console.c

index 4525cc7..f5e8814 100644 (file)
--- a/console.c
+++ b/console.c
@@ -1087,7 +1087,7 @@ void console_select(unsigned int index)
     if (s) {
         DisplayState *ds = s->ds;
 
-        if (active_console->cursor_timer) {
+        if (active_console && active_console->cursor_timer) {
             qemu_del_timer(active_console->cursor_timer);
         }
         active_console = s;