Correct AtspiTable usage 03/296203/1 accepted/tizen/unified/20230725.013004
authorArtur Świgoń <a.swigon@samsung.com>
Fri, 21 Jul 2023 12:14:36 +0000 (14:14 +0200)
committerArtur Świgoń <a.swigon@samsung.com>
Fri, 21 Jul 2023 12:14:39 +0000 (14:14 +0200)
Somewhat confusingly, atspi_table_cell_get_table() returns an
AtspiAccessible, not an AtspiTable. The AtspiAccessible can be
then passed to atspi_accessible_get_table_iface() to obtain an
AtspiTable. Also, due to the increased complexity, use `goto`
to clean up all objects at the end.

Change-Id: I912d6b1fc252a52c0d7c9f29c9376d3f036634a1

src/utils.c

index 9ad8130a5cb7732d66d79bc1fba7a990a5db3bae..d382c57403275fe4ac339c7500176617051fcd17 100644 (file)
@@ -349,24 +349,27 @@ Eina_Bool object_get_position_in_table(AtspiAccessible *object, int *row, int *c
        GError *err = NULL;
        atspi_table_cell_get_row_column_span(table_cell, row, column, &row_span, &column_span, &err);
 
+       Eina_Bool status = EINA_FALSE;
+       AtspiAccessible *table_accessible = NULL;
+       AtspiTable *table = NULL;
+
        if (err) {
                ERROR("failed to get cell position in table");
                GERROR_CHECK(err);
-               g_object_unref(table_cell);
-               return EINA_FALSE;
+               goto end;
        }
 
        if (*row < 0 || *column < 0) {
                ERROR("invalid cell position in table");
-               g_object_unref(table_cell);
-               return EINA_FALSE;
+               goto end;
        }
 
-       AtspiTable *table = atspi_table_cell_get_table(table_cell, NULL);
-       if (!table) {
+       table_accessible = atspi_table_cell_get_table(table_cell, NULL);
+       table = atspi_accessible_get_table_iface(table_accessible); // null is safe
+
+       if (!table_accessible || !table) {
                ERROR("table cell object is not in table");
-               g_object_unref(table_cell);
-               return EINA_FALSE;
+               goto end;
        }
 
        if (table_row_count && table_column_count && table_caption) {
@@ -374,18 +377,14 @@ Eina_Bool object_get_position_in_table(AtspiAccessible *object, int *row, int *c
 
                if (*table_row_count < 0) {
                        ERROR("invalid row count in table");
-                       g_object_unref(table_cell);
-                       g_object_unref(table);
-                       return EINA_FALSE;
+                       goto end;
                }
 
                *table_column_count = atspi_table_get_n_columns(table, NULL);
 
                if (*table_column_count < 0) {
                        ERROR("invalid column count in table");
-                       g_object_unref(table_cell);
-                       g_object_unref(table);
-                       return EINA_FALSE;
+                       goto end;
                }
 
                AtspiAccessible* caption_object = atspi_table_get_caption(table, NULL);
@@ -395,10 +394,14 @@ Eina_Bool object_get_position_in_table(AtspiAccessible *object, int *row, int *c
                }
        }
 
-       *table_unique_id = atspi_accessible_get_unique_id(table, NULL);
+       *table_unique_id = atspi_accessible_get_unique_id(table_accessible, NULL);
 
-       g_object_unref(table);
-       g_object_unref(table_cell);
+       status = EINA_TRUE;
 
-       return EINA_TRUE;
+end:
+       if (table) g_object_unref(table);
+       if (table_accessible) g_object_unref(table_accessible);
+       if (table_cell) g_object_unref(table_cell);
+
+       return status;
 }