From: Linus Torvalds Date: Wed, 31 Aug 2011 23:40:22 +0000 (-0700) Subject: Do something half-way sane (no SIGSEGV) when there are no dives X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=968aa28155b3a55b558d16e3a46dfd5c887dc3c6;p=ext%2Fsubsurface.git Do something half-way sane (no SIGSEGV) when there are no dives It just leaves ugly blank areas, but whatever. Signed-off-by: Linus Torvalds --- diff --git a/info.c b/info.c index efd17f8..bef3f1d 100644 --- a/info.c +++ b/info.c @@ -12,6 +12,13 @@ void update_dive_info(struct dive *dive) struct tm *tm; char buffer[80]; + if (!dive) { + gtk_entry_set_text(GTK_ENTRY(datetime), "no dive"); + gtk_entry_set_text(GTK_ENTRY(depth), ""); + gtk_entry_set_text(GTK_ENTRY(duration), ""); + return; + } + tm = gmtime(&dive->when); snprintf(buffer, sizeof(buffer), "%04d-%02d-%02d " diff --git a/profile.c b/profile.c index f898be7..9d84ff2 100644 --- a/profile.c +++ b/profile.c @@ -100,7 +100,7 @@ static void plot(cairo_t *cr, int w, int h, struct dive *dive, int samples, stru static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data) { - struct dive *dive = dive_table.dives[selected_dive]; + struct dive *dive = current_dive; cairo_t *cr; int w,h; @@ -111,7 +111,7 @@ static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer cairo_set_source_rgb(cr, 0, 0, 0); cairo_paint(cr); - if (dive->samples) + if (dive && dive->samples) plot(cr, w, h, dive, dive->samples, dive->sample); cairo_destroy(cr);