From: Radoslaw Cybulski Date: Tue, 20 Dec 2016 12:35:19 +0000 (+0100) Subject: fix cppcheck issues (src/screen_reader_spi.c) X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1e4c67c010b43a85d4686ef34ad2fe8c6ed529d0;p=platform%2Fcore%2Faccessibility%2Fscreen-reader.git fix cppcheck issues (src/screen_reader_spi.c) Change-Id: Ia9ac1df1487cdf666b7e79bb8d24f1d97e056aed --- diff --git a/src/screen_reader_spi.c b/src/screen_reader_spi.c index 00aeac11..0315d371 100644 --- a/src/screen_reader_spi.c +++ b/src/screen_reader_spi.c @@ -76,34 +76,30 @@ char *generate_description_for_subtree(AtspiAccessible *obj) return strdup(""); int child_count = atspi_accessible_get_child_count(obj, NULL); - DEBUG("There is %d children inside this filler", child_count); if (!child_count) return strdup(""); + char ret[256] = ""; int i; - char *name = NULL; - char *below = NULL; - char ret[256] = "\0"; - AtspiAccessible *child = NULL; - for (i = 0; i < child_count; i++) { - child = atspi_accessible_get_child_at_index(obj, i, NULL); - name = atspi_accessible_get_name(child, NULL); + if (i > 0) + strncat(ret, ", ", sizeof(ret) - 2 - 1); + + AtspiAccessible *child = atspi_accessible_get_child_at_index(obj, i, NULL); + char *name = atspi_accessible_get_name(child, NULL); DEBUG("%d child name:%s", i, name); - if (name && strncmp(name, "\0", 1)) { + if (name && name[0] != 0) { strncat(ret, name, sizeof(ret) - strlen(ret) - 1); + strncat(ret, " ", sizeof(ret) - strlen(ret) - 1); } - strncat(ret, " ", sizeof(ret) - strlen(ret) - 1); - below = generate_description_for_subtree(child); - - if (strncmp(below, "\0", 1)) { + char *below = generate_description_for_subtree(child); + if (below && below[0] != 0) strncat(ret, below, sizeof(ret) - strlen(ret) - 1); - } g_object_unref(child); free(below); @@ -174,16 +170,10 @@ static char *spi_on_caret_move_get_text(AtspiEvent *event, void *user_data) } Screen_Reader_Spi_Data_t *spi_data = (Screen_Reader_Spi_Data_t *)user_data; - spi_data->currently_focused = event->source; - char *return_text; - gchar *text = NULL; - char *added_text = NULL; - int ret = -1; - - if (spi_data->last_caret_position == event->detail1) { // ignore fake moves, selection moves etc. + if (spi_data->last_caret_position == event->detail1) // ignore fake moves, selection moves etc. return NULL; - } + spi_data->last_caret_position = event->detail1; if (spi_data->ignore_next_caret_move) { @@ -192,34 +182,33 @@ static char *spi_on_caret_move_get_text(AtspiEvent *event, void *user_data) } AtspiText *text_interface = atspi_accessible_get_text_iface(spi_data->currently_focused); - if (text_interface) { DEBUG("->->->->->-> WIDGET CARET MOVED: %s <-<-<-<-<-<-<-", atspi_accessible_get_name(spi_data->currently_focused, NULL)); int char_count = (int)atspi_text_get_character_count(text_interface, NULL); int caret_pos = atspi_text_get_caret_offset(text_interface, NULL); - text = atspi_text_get_text(text_interface, caret_pos, caret_pos + 1, NULL); + gchar *text = atspi_text_get_text(text_interface, caret_pos, caret_pos + 1, NULL); + char *added_test = NULL; if (!caret_pos) { DEBUG("MIN POSITION REACHED"); added_text = _("IDS_REACHED_MIN_POS"); - } else if (char_count == caret_pos) { + } + else if (char_count == caret_pos) { DEBUG("MAX POSITION REACHED"); added_text = _("IDS_REACHED_MAX_POS"); - } + if (added_text) - ret = asprintf(&return_text, "%s %s", text, added_text); + asprintf(&return_text, "%s %s", text, added_text); else - ret = asprintf(&return_text, "%s", text); - + asprintf(&return_text, "%s", text); g_free(text); + g_object_unref(text_interface); } - if (ret < 0) { + if (ret < 0) ERROR(MEMORY_ERROR); - return NULL; - } return return_text; }