aboutsummaryrefslogtreecommitdiff
path: root/gtk.c
diff options
context:
space:
mode:
authorAsher Gordon <AsDaGo@posteo.net>2019-12-24 00:44:30 -0500
committerSimon Tatham <anakin@pobox.com>2019-12-25 06:28:52 +0000
commitce69911077ce1399ae3626c9f66737c4586db18a (patch)
treeb89cb458b41d540f635cbfe36dac9b7d86d96fe8 /gtk.c
parent1c0c49dd5cd8df6ae87f7be5371be84589fa2662 (diff)
downloadpuzzles-ce69911077ce1399ae3626c9f66737c4586db18a.zip
puzzles-ce69911077ce1399ae3626c9f66737c4586db18a.tar.gz
puzzles-ce69911077ce1399ae3626c9f66737c4586db18a.tar.bz2
puzzles-ce69911077ce1399ae3626c9f66737c4586db18a.tar.xz
Don't segfault when no icons are available.
When no icons are available, n_xpm_icons will be 0, and menu_about_event() will try to access xpm_icons[n_xpm_icons-1]. Since n_xpm_icons is 0, this becomes xpm_icons[-1] which is an invalid value, causing a segfault. Instead, check if n_xpm_icons is 0, and if so, don't pass any icon to gtk_show_about_dialog().
Diffstat (limited to 'gtk.c')
-rw-r--r--gtk.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/gtk.c b/gtk.c
index 4565836..1117243 100644
--- a/gtk.c
+++ b/gtk.c
@@ -2395,18 +2395,31 @@ static void menu_about_event(GtkMenuItem *menuitem, gpointer data)
frontend *fe = (frontend *)data;
#if GTK_CHECK_VERSION(3,0,0)
+# define ABOUT_PARAMS \
+ "program-name", thegame.name, \
+ "version", ver, \
+ "comments", "Part of Simon Tatham's Portable Puzzle Collection"
+
extern char *const *const xpm_icons[];
extern const int n_xpm_icons;
- GdkPixbuf *icon = gdk_pixbuf_new_from_xpm_data
- ((const gchar **)xpm_icons[n_xpm_icons-1]);
- gtk_show_about_dialog
- (GTK_WINDOW(fe->window),
- "program-name", thegame.name,
- "version", ver,
- "comments", "Part of Simon Tatham's Portable Puzzle Collection",
- "logo", icon,
- (const gchar *)NULL);
- g_object_unref(G_OBJECT(icon));
+
+ if (n_xpm_icons) {
+ GdkPixbuf *icon = gdk_pixbuf_new_from_xpm_data
+ ((const gchar **)xpm_icons[n_xpm_icons-1]);
+
+ gtk_show_about_dialog
+ (GTK_WINDOW(fe->window),
+ ABOUT_PARAMS,
+ "logo", icon,
+ (const gchar *)NULL);
+ g_object_unref(G_OBJECT(icon));
+ }
+ else {
+ gtk_show_about_dialog
+ (GTK_WINDOW(fe->window),
+ ABOUT_PARAMS,
+ (const gchar *)NULL);
+ }
#else
char titlebuf[256];
char textbuf[1024];