From cee4ebf37cd991728bab1a64eccdd031a8f0eb3c Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Sat, 1 Jul 2006 13:16:52 +0000 Subject: [PATCH] Fix a segfault on Go to tag defn/decl if no files have tags. Add utils_find_tm_tag git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@516 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 3 +++ src/callbacks.c | 37 +++++++++++++++++++------------------ src/utils.c | 14 ++++++++++++++ src/utils.h | 2 ++ 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7c3c58cc..4c0e707e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,9 @@ * src/callbacks.c: Prevent a segfault if the VTE has not been loaded. * src/utils.c, src/utils.h, src/msgwindow.c: Add utils_get_current_time_string and fix getting the time string. + * src/utils.c, src/utils.h, src/callbacks.c: + Fix a segfault on Go to tag defn/decl if no files have tags. + Add utils_find_tm_tag. 2006-06-30 Enrico Tröger diff --git a/src/callbacks.c b/src/callbacks.c index 10c86ade..65437dd8 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -1340,39 +1340,40 @@ on_goto_tag_activate (GtkMenuItem *menuitem, gpointer user_data) { gint type; - guint i, j; + guint j; const GPtrArray *tags; + TMTag *tmtag; if (menuitem == GTK_MENU_ITEM(lookup_widget(app->popup_menu, "goto_tag_definition1"))) type = tm_tag_function_t; else type = tm_tag_prototype_t; - for (j = 0; j < app->tm_workspace->work_objects->len; j++) + if (app->tm_workspace->work_objects != NULL) { - tags = tm_tags_extract(TM_WORK_OBJECT(app->tm_workspace->work_objects->pdata[j])->tags_array, type); - if (tags) + for (j = 0; j < app->tm_workspace->work_objects->len; j++) { - for (i = 0; i < tags->len; ++i) + tags = tm_tags_extract( + TM_WORK_OBJECT(app->tm_workspace->work_objects->pdata[j])->tags_array, + type); + if (tags == NULL) continue; + + tmtag = utils_find_tm_tag(tags, current_word); + if (tmtag != NULL) { - if (utils_strcmp(TM_TAG(tags->pdata[i])->name, current_word)) - { - if (! utils_goto_file_line( - TM_TAG(tags->pdata[i])->atts.entry.file->work_object.file_name, - TRUE, - TM_TAG(tags->pdata[i])->atts.entry.line)) - { - utils_beep(); - msgwin_status_add(_("Declaration or definition of \"%s()\" not found"), current_word); - } - return; - } + if (! utils_goto_file_line( + tmtag->atts.entry.file->work_object.file_name, + TRUE, tmtag->atts.entry.line)) break; + return; } } } // if we are here, there was no match and we are beeping ;-) utils_beep(); - msgwin_status_add(_("Declaration or definition of \"%s()\" not found"), current_word); + if (type == tm_tag_prototype_t) + msgwin_status_add(_("Declaration of \"%s()\" not found"), current_word); + else + msgwin_status_add(_("Definition of \"%s()\" not found"), current_word); } diff --git a/src/utils.c b/src/utils.c index 65930f43..ec27d8b8 100644 --- a/src/utils.c +++ b/src/utils.c @@ -2496,3 +2496,17 @@ gchar *utils_get_current_time_string() } +TMTag *utils_find_tm_tag(const GPtrArray *tags, const gchar *tag_name) +{ + guint i; + g_return_val_if_fail(tags != NULL, NULL); + + for (i = 0; i < tags->len; ++i) + { + if (utils_strcmp(TM_TAG(tags->pdata[i])->name, tag_name)) + return TM_TAG(tags->pdata[i]); + } + return NULL; +} + + diff --git a/src/utils.h b/src/utils.h index 74ab57fb..2a8d8c69 100644 --- a/src/utils.h +++ b/src/utils.h @@ -220,4 +220,6 @@ void utils_parse_compiler_error_line(const gchar *string, gchar **filename, gint // returned string must be freed. gchar *utils_get_current_time_string(); +TMTag *utils_find_tm_tag(const GPtrArray *tags, const gchar *tag_name); + #endif