diff --git a/src/virt-viewer-util.c b/src/virt-viewer-util.c index 069586a..9e52b87 100644 --- a/src/virt-viewer-util.c +++ b/src/virt-viewer-util.c @@ -521,6 +521,7 @@ displays_cmp(const void *p1, const void *p2, gpointer user_data) guint j = *(guint*)p2; GdkRectangle *m1 = g_hash_table_lookup(displays, GINT_TO_POINTER(i)); GdkRectangle *m2 = g_hash_table_lookup(displays, GINT_TO_POINTER(j)); + g_return_val_if_fail(m1 != NULL && m2 != NULL, 0); diff = m1->x - m2->x; if (diff == 0) diff = m1->y - m2->y; @@ -571,6 +572,7 @@ virt_viewer_align_monitors_linear(GHashTable *displays) guint nth = sorted_displays[i]; g_assert(nth < ndisplays); GdkRectangle *rect = g_hash_table_lookup(displays, GINT_TO_POINTER(nth)); + g_return_if_fail(rect != NULL); rect->x = x; rect->y = 0; x += rect->width; @@ -603,6 +605,7 @@ virt_viewer_shift_monitors_to_origin(GHashTable *displays) g_hash_table_iter_init(&iter, displays); while (g_hash_table_iter_next(&iter, NULL, &value)) { GdkRectangle *display = value; + g_return_if_fail(display != NULL); if (display->width > 0 && display->height > 0) { xmin = MIN(xmin, display->x); ymin = MIN(ymin, display->y); diff --git a/tests/test-monitor-alignment.c b/tests/test-monitor-alignment.c index 4d0bf9d..522483f 100644 --- a/tests/test-monitor-alignment.c +++ b/tests/test-monitor-alignment.c @@ -100,6 +100,24 @@ test_monitor_shift(void) const TestCase test_cases[] = { { 0, {NULL}, {NULL}, 0, {NULL} + },{ + 1, + {NULL}, + {NULL}, + G_LOG_LEVEL_CRITICAL, + {"*assertion 'display != NULL' failed"} + },{ + 2, + {NULL, &rects[0]}, + {NULL, &rects[0]}, + G_LOG_LEVEL_CRITICAL, + {"*assertion 'display != NULL' failed"} + },{ + 2, + {&rects[2], NULL}, + {&rects[2], NULL}, + G_LOG_LEVEL_CRITICAL, + {"*assertion 'display != NULL' failed"} },{ 2, {&rects[0], &rects[0]}, @@ -139,6 +157,31 @@ test_monitor_align_linear(void) const TestCase test_cases[] = { { 0, {NULL}, {NULL}, 0, {NULL} + },{ + 1, + {NULL}, + {NULL}, + G_LOG_LEVEL_CRITICAL, + {"*assertion 'rect != NULL' failed"} + },{ + 2, + {NULL, &rects[1]}, + {NULL, &rects[1]}, + G_LOG_LEVEL_CRITICAL, + { + "*displays_cmp: assertion 'm1 != NULL && m2 != NULL' failed", + "*assertion 'rect != NULL' failed" + } + },{ + 3, + {&rects[1], NULL, &rects[0]}, + {&rects[3], NULL, &rects[0]}, + G_LOG_LEVEL_CRITICAL, + { + "*displays_cmp: assertion 'm1 != NULL && m2 != NULL' failed", + "*displays_cmp: assertion 'm1 != NULL && m2 != NULL' failed", + "*assertion 'rect != NULL' failed" + } },{ 2, {&rects[0], &rects[1]},