mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Bug 798531 - Selecting "Print" from the file menu on a report...
crashes gnucash Ensure that every call to gnc_prefs_get_string correctly handles both a NULL or empty string return value without crashing or leaking.
This commit is contained in:
parent
10facd40c3
commit
564d73a553
@ -197,15 +197,15 @@ gnc_history_add_file (const char *newfile)
|
||||
{
|
||||
from = gnc_history_index_to_pref_name(i);
|
||||
filename = gnc_prefs_get_string(GNC_PREFS_GROUP_HISTORY, from);
|
||||
if (filename)
|
||||
if (filename && *filename)
|
||||
{
|
||||
gnc_prefs_set_string(GNC_PREFS_GROUP_HISTORY, to, filename);
|
||||
g_free(filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
gnc_prefs_reset(GNC_PREFS_GROUP_HISTORY, to);
|
||||
}
|
||||
g_free(filename);
|
||||
g_free(to);
|
||||
to = from;
|
||||
}
|
||||
|
@ -606,13 +606,12 @@ gnc_ui_print_restore_dialog(PrintCheckDialog *pcd)
|
||||
|
||||
/* Options page */
|
||||
guid = gnc_prefs_get_string (GNC_PREFS_GROUP, GNC_PREF_CHECK_FORMAT_GUID);
|
||||
if (guid == NULL)
|
||||
if (!(guid && *guid))
|
||||
gtk_combo_box_set_active(GTK_COMBO_BOX(pcd->format_combobox), 0);
|
||||
else if (strcmp(guid, "custom") == 0)
|
||||
{
|
||||
gtk_combo_box_set_active(GTK_COMBO_BOX(pcd->format_combobox),
|
||||
pcd->format_max - 1);
|
||||
g_free (guid);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -625,8 +624,8 @@ gnc_ui_print_restore_dialog(PrintCheckDialog *pcd)
|
||||
{
|
||||
gtk_combo_box_set_active(GTK_COMBO_BOX(pcd->format_combobox), 0);
|
||||
}
|
||||
g_free (guid);
|
||||
}
|
||||
g_free (guid);
|
||||
|
||||
active = gnc_prefs_get_int(GNC_PREFS_GROUP, GNC_PREF_CHECK_POSITION);
|
||||
|
||||
@ -642,7 +641,7 @@ gnc_ui_print_restore_dialog(PrintCheckDialog *pcd)
|
||||
if (active == QOF_DATE_FORMAT_CUSTOM)
|
||||
{
|
||||
format = gnc_prefs_get_string (GNC_PREFS_GROUP, GNC_PREF_DATE_FORMAT_USER);
|
||||
if (format)
|
||||
if (format && *format)
|
||||
{
|
||||
gnc_date_format_set_custom(GNC_DATE_FORMAT(pcd->date_format), format);
|
||||
g_free(format);
|
||||
@ -1701,7 +1700,7 @@ gnc_ui_print_check_dialog_create(GtkWidget *parent,
|
||||
|
||||
/* Default font (set in preferences) */
|
||||
font = gnc_prefs_get_string(GNC_PREFS_GROUP, GNC_PREF_DEFAULT_FONT);
|
||||
pcd->default_font = font ? font : g_strdup(DEFAULT_FONT);
|
||||
pcd->default_font = font && *font ? font : g_strdup(DEFAULT_FONT);
|
||||
|
||||
/* Update the combo boxes bases on the available check formats */
|
||||
initialize_format_combobox(pcd);
|
||||
|
@ -1812,7 +1812,7 @@ static gchar *report_create_jobname(GncPluginPageReportPrivate *priv)
|
||||
char *format_code = gnc_prefs_get_string (GNC_PREFS_GROUP_REPORT_PDFEXPORT,
|
||||
GNC_PREF_FILENAME_DATE_FMT);
|
||||
const gchar *date_format_string;
|
||||
if (*format_code == '\0')
|
||||
if (!(format_code && *format_code))
|
||||
{
|
||||
g_free(format_code);
|
||||
format_code = g_strdup("locale");
|
||||
@ -1872,8 +1872,17 @@ static gchar *report_create_jobname(GncPluginPageReportPrivate *priv)
|
||||
// Look up the sprintf format of the output name from the preferences database
|
||||
char* format = gnc_prefs_get_string(GNC_PREFS_GROUP_REPORT_PDFEXPORT, GNC_PREF_FILENAME_FMT);
|
||||
|
||||
job_name = g_strdup_printf(format, report_name, report_number, job_date);
|
||||
|
||||
if (format && *format)
|
||||
{
|
||||
job_name = g_strdup_printf(format, report_name,
|
||||
report_number, job_date);
|
||||
}
|
||||
else
|
||||
{
|
||||
PWARN("No GNC_PREF_FILENAME_FMT!");
|
||||
job_name = g_strdup_printf ("%s %s %s", report_name,
|
||||
report_number, job_date);
|
||||
}
|
||||
g_free(format);
|
||||
}
|
||||
g_free (report_name);
|
||||
|
@ -674,7 +674,7 @@ gnc_plugin_ab_cmd_mt940_import(GtkAction *action, GncMainWindowActionData *data)
|
||||
GNC_PREF_FORMAT_SWIFT940);
|
||||
gnc_main_window = data->window;
|
||||
gnc_file_aqbanking_import (GTK_WINDOW (gnc_main_window),
|
||||
"swift", format ? format : "swift-mt940", FALSE);
|
||||
"swift", format && *format ? format : "swift-mt940", FALSE);
|
||||
g_free(format);
|
||||
}
|
||||
|
||||
@ -685,7 +685,7 @@ gnc_plugin_ab_cmd_mt942_import(GtkAction *action, GncMainWindowActionData *data)
|
||||
GNC_PREF_FORMAT_SWIFT942);
|
||||
gnc_main_window = data->window;
|
||||
gnc_file_aqbanking_import (GTK_WINDOW (gnc_main_window),
|
||||
"swift", format ? format : "swift-mt942", FALSE);
|
||||
"swift", format && *format? format : "swift-mt942", FALSE);
|
||||
g_free(format);
|
||||
}
|
||||
|
||||
@ -696,7 +696,7 @@ gnc_plugin_ab_cmd_dtaus_import(GtkAction *action, GncMainWindowActionData *data)
|
||||
GNC_PREF_FORMAT_DTAUS);
|
||||
gnc_main_window = data->window;
|
||||
gnc_file_aqbanking_import (GTK_WINDOW (gnc_main_window),
|
||||
"dtaus", format ? format : "default", FALSE);
|
||||
"dtaus", format && *format ? format : "default", FALSE);
|
||||
g_free(format);
|
||||
}
|
||||
|
||||
@ -708,7 +708,7 @@ gnc_plugin_ab_cmd_dtaus_importsend(GtkAction *action,
|
||||
GNC_PREF_FORMAT_DTAUS);
|
||||
gnc_main_window = data->window;
|
||||
gnc_file_aqbanking_import (GTK_WINDOW (gnc_main_window),
|
||||
"dtaus", format ? format : "default", TRUE);
|
||||
"dtaus", format && *format ? format : "default", TRUE);
|
||||
g_free(format);
|
||||
}
|
||||
|
||||
|
@ -210,13 +210,15 @@ gnc_get_default_directory (const gchar *section)
|
||||
gchar *dir;
|
||||
|
||||
dir = gnc_prefs_get_string (section, GNC_PREF_LAST_PATH);
|
||||
if (!dir)
|
||||
if (!(dir && *dir))
|
||||
{
|
||||
g_free (dir); // if it's ""
|
||||
#ifdef G_OS_WIN32
|
||||
dir = g_strdup (g_get_user_data_dir ()); /* equivalent of "My Documents" */
|
||||
#else
|
||||
dir = g_strdup (g_get_home_dir ());
|
||||
#endif
|
||||
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
@ -1176,7 +1178,8 @@ gnc_default_currency_common (gchar *requested_currency,
|
||||
mnemonic = gnc_prefs_get_string(section, GNC_PREF_CURRENCY_OTHER);
|
||||
currency = gnc_commodity_table_lookup(gnc_get_current_commodities(),
|
||||
GNC_COMMODITY_NS_CURRENCY, mnemonic);
|
||||
DEBUG("mnemonic %s, result %p", mnemonic ? mnemonic : "(null)", currency);
|
||||
DEBUG("mnemonic %s, result %p",
|
||||
mnemonic && *mnemonic ? mnemonic : "(null)", currency);
|
||||
g_free(mnemonic);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user