mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Bug #642445 [PATCH] Segfault when tip_of_the_day.list is empty
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20303 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
8650eec61c
commit
d7073fb148
@ -80,7 +80,7 @@ gnc_new_tip_number (GtkWidget *widget,
|
|||||||
gint offset)
|
gint offset)
|
||||||
{
|
{
|
||||||
GtkWidget *textview;
|
GtkWidget *textview;
|
||||||
gchar **tip_components, **tip_args;
|
gchar **tip_components;
|
||||||
gchar *tip;
|
gchar *tip;
|
||||||
|
|
||||||
ENTER("widget %p, offset %d", widget, offset);
|
ENTER("widget %p, offset %d", widget, offset);
|
||||||
@ -92,10 +92,31 @@ gnc_new_tip_number (GtkWidget *widget,
|
|||||||
current_tip_number = 0;
|
current_tip_number = 0;
|
||||||
gnc_gconf_set_int(GCONF_SECTION, KEY_CURRENT_TIP, current_tip_number, NULL);
|
gnc_gconf_set_int(GCONF_SECTION, KEY_CURRENT_TIP, current_tip_number, NULL);
|
||||||
|
|
||||||
|
/* A tip consists of a translatable string, which might contain a %s
|
||||||
|
* placeholder, optionally followed by a | and a (non-translated)
|
||||||
|
* string to put in the placeholder. For example:
|
||||||
|
*
|
||||||
|
* Welcome to GnuCash version %s|2.4
|
||||||
|
*/
|
||||||
tip_components = g_strsplit(tip_list[current_tip_number], "|", 0);
|
tip_components = g_strsplit(tip_list[current_tip_number], "|", 0);
|
||||||
tip_args = &tip_components[1];
|
/* If the tip is empty, g_strisplit will return an empty list. This
|
||||||
|
* shouldn't normally happen, but make sure we don't crash just in
|
||||||
|
* case */
|
||||||
|
if (tip_components[0] == NULL)
|
||||||
|
{
|
||||||
|
tip = g_strdup("");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Use printf to do the substitution. Note that if there is no |
|
||||||
|
* in the tip, tip_components[1] will be the terminating NULL,
|
||||||
|
* so this will never cause an out-of-bounds array access.
|
||||||
|
*/
|
||||||
|
tip = g_strdup_printf( _(tip_components[0]), tip_components[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
textview = gnc_glade_lookup_widget(widget, "tip_textview");
|
textview = gnc_glade_lookup_widget(widget, "tip_textview");
|
||||||
tip = g_strdup_printf( _(tip_components[0]), tip_components[1]);
|
|
||||||
g_strfreev(tip_components);
|
g_strfreev(tip_components);
|
||||||
gtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)),
|
gtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)),
|
||||||
tip, -1);
|
tip, -1);
|
||||||
@ -207,6 +228,17 @@ gnc_totd_initialize (void)
|
|||||||
|
|
||||||
g_free(contents);
|
g_free(contents);
|
||||||
g_free(filename);
|
g_free(filename);
|
||||||
|
|
||||||
|
/* Don't continue when no tips were found, to prevent
|
||||||
|
* gnc_new_tip_number doesn't handle that case (it would try to
|
||||||
|
* display the terminating NULL). There's nothing to show
|
||||||
|
* anyway...*/
|
||||||
|
if (tip_count == 0)
|
||||||
|
{
|
||||||
|
PWARN("No tips found - Tips of the day window won't be displayed.");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user