divelist.c:icon_click_cb(): check if a GtkTreePath is found

In icon_click_cb() we need to check if a correct GtkTreePath is found
(using gtk_tree_view_get_path_at_pos()) before requesting a GtkTreeIter
for it.

Without this patch a bug is reproducible, where the user may click
outside of the GtkTreeView entries, but still in the GtkTreeView -
e.g. when only one entry is available.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Lubomir I. Ivanov 2013-01-23 17:48:59 +02:00 committed by Dirk Hohndel
parent c149921df4
commit b1db60ba47

View file

@ -1700,15 +1700,15 @@ static void show_gps_location_cb(GtkWidget *menuitem, struct dive *dive)
gboolean icon_click_cb(GtkWidget *w, GdkEventButton *event, gpointer data) gboolean icon_click_cb(GtkWidget *w, GdkEventButton *event, gpointer data)
{ {
#if HAVE_OSM_GPS_MAP #if HAVE_OSM_GPS_MAP
GtkTreePath *path; GtkTreePath *path = NULL;
GtkTreeIter iter; GtkTreeIter iter;
GtkTreeViewColumn *col; GtkTreeViewColumn *col;
int idx; int idx;
struct dive *dive; struct dive *dive;
/* left click ? */ /* left click ? */
if (event->button == 1) { if (event->button == 1 &&
gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(dive_list.tree_view), event->x, event->y, &path, &col, NULL, NULL); gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(dive_list.tree_view), event->x, event->y, &path, &col, NULL, NULL)) {
/* is it the icon column ? (we passed the correct column in when registering the callback) */ /* is it the icon column ? (we passed the correct column in when registering the callback) */
if (col == data) { if (col == data) {
gtk_tree_model_get_iter(MODEL(dive_list), &iter, path); gtk_tree_model_get_iter(MODEL(dive_list), &iter, path);
@ -1717,6 +1717,7 @@ gboolean icon_click_cb(GtkWidget *w, GdkEventButton *event, gpointer data)
if (dive && dive_has_location(dive)) if (dive && dive_has_location(dive))
show_gps_location(dive); show_gps_location(dive);
} }
if (path)
gtk_tree_path_free(path); gtk_tree_path_free(path);
} }
#endif #endif