소스 검색

ui: add precondition for dpy_get_ui_info()

Ensure that it only get called when dpy_ui_info_supported(). The
function should always return a result. There should be a non-null
console or active_console.

Modify the argument to be const as well.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Albert Esteve <aesteve@redhat.com>
Marc-André Lureau 1 년 전
부모
커밋
a92e7bb4ca
2개의 변경된 파일4개의 추가작업 그리고 2개의 파일을 삭제
  1. 1 1
      include/ui/console.h
  2. 3 1
      ui/console.c

+ 1 - 1
include/ui/console.h

@@ -329,7 +329,7 @@ void update_displaychangelistener(DisplayChangeListener *dcl,
                                   uint64_t interval);
                                   uint64_t interval);
 void unregister_displaychangelistener(DisplayChangeListener *dcl);
 void unregister_displaychangelistener(DisplayChangeListener *dcl);
 
 
-bool dpy_ui_info_supported(QemuConsole *con);
+bool dpy_ui_info_supported(const QemuConsole *con);
 const QemuUIInfo *dpy_get_ui_info(const QemuConsole *con);
 const QemuUIInfo *dpy_get_ui_info(const QemuConsole *con);
 int dpy_set_ui_info(QemuConsole *con, QemuUIInfo *info, bool delay);
 int dpy_set_ui_info(QemuConsole *con, QemuUIInfo *info, bool delay);
 
 

+ 3 - 1
ui/console.c

@@ -801,7 +801,7 @@ static void dpy_set_ui_info_timer(void *opaque)
     con->hw_ops->ui_info(con->hw, head, &con->ui_info);
     con->hw_ops->ui_info(con->hw, head, &con->ui_info);
 }
 }
 
 
-bool dpy_ui_info_supported(QemuConsole *con)
+bool dpy_ui_info_supported(const QemuConsole *con)
 {
 {
     if (con == NULL) {
     if (con == NULL) {
         con = active_console;
         con = active_console;
@@ -815,6 +815,8 @@ bool dpy_ui_info_supported(QemuConsole *con)
 
 
 const QemuUIInfo *dpy_get_ui_info(const QemuConsole *con)
 const QemuUIInfo *dpy_get_ui_info(const QemuConsole *con)
 {
 {
+    assert(dpy_ui_info_supported(con));
+
     if (con == NULL) {
     if (con == NULL) {
         con = active_console;
         con = active_console;
     }
     }