From: Andrej Kacian Date: Thu, 22 Sep 2016 12:02:09 +0000 (+0200) Subject: Better handle NULL path arguments in w32_filesel.c X-Git-Tag: 3.14.1~48 X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=commitdiff_plain;h=3a5f7d5d11e019046db183125e916e94825f177c;hp=2eea744e656d5705be2b4d610dbf7f3a8ae79928 Better handle NULL path arguments in w32_filesel.c Fixes bug #3697. --- diff --git a/src/gtk/w32_filesel.c b/src/gtk/w32_filesel.c index 09dd0b00b..651ad8da4 100644 --- a/src/gtk/w32_filesel.c +++ b/src/gtk/w32_filesel.c @@ -115,28 +115,26 @@ static const gboolean _file_open_dialog(const gchar *path, const gchar *title, pthread_t pt; #endif - if (path != NULL) { - /* Path needs to be converted to UTF-16, so that the native chooser - * can understand it. */ - path16 = g_utf8_to_utf16(path, -1, NULL, NULL, &error); - if (error != NULL) { - alertpanel_error(_("Could not convert file path to UTF-16:\n\n%s"), - error->message); - debug_print("file path '%s' conversion to UTF-16 failed\n", path); - g_error_free(error); - error = NULL; - return FALSE; - } + /* Path needs to be converted to UTF-16, so that the native chooser + * can understand it. */ + path16 = g_utf8_to_utf16(path ? path : "", + -1, NULL, NULL, &error); + if (error != NULL) { + alertpanel_error(_("Could not convert file path to UTF-16:\n\n%s"), + error->message); + debug_print("file path '%s' conversion to UTF-16 failed\n", path); + g_error_free(error); + error = NULL; + return FALSE; } - if (title != NULL) { - /* Chooser dialog title needs to be UTF-16 as well. */ - title16 = g_utf8_to_utf16(title, -1, NULL, NULL, &error); - if (error != NULL) { - debug_print("dialog title '%s' conversion to UTF-16 failed\n", title); - g_error_free(error); - error = NULL; - } + /* Chooser dialog title needs to be UTF-16 as well. */ + title16 = g_utf8_to_utf16(title ? title : "", + -1, NULL, NULL, &error); + if (error != NULL) { + debug_print("dialog title '%s' conversion to UTF-16 failed\n", title); + g_error_free(error); + error = NULL; } o.lStructSize = sizeof(OPENFILENAME); @@ -325,7 +323,7 @@ gchar *filesel_select_file_save(const gchar *title, const gchar *path) #endif /* Find the filename part, if any */ - if (path[strlen(path)-1] == G_DIR_SEPARATOR) { + if (path == NULL || path[strlen(path)-1] == G_DIR_SEPARATOR) { filename = ""; } else if ((filename = strrchr(path, G_DIR_SEPARATOR)) != NULL) { filename++; @@ -450,7 +448,8 @@ gchar *filesel_select_file_open_folder(const gchar *title, const gchar *path) /* Path needs to be converted to UTF-16, so that the native chooser * can understand it. */ - path16 = g_utf8_to_utf16(path, -1, NULL, &conv_items, &error); + path16 = g_utf8_to_utf16(path ? path : "", + -1, NULL, &conv_items, &error); if (error != NULL) { alertpanel_error(_("Could not convert file path to UTF-16:\n\n%s"), error->message); @@ -460,7 +459,8 @@ gchar *filesel_select_file_open_folder(const gchar *title, const gchar *path) } /* Chooser dialog title needs to be UTF-16 as well. */ - title16 = g_utf8_to_utf16(title, -1, NULL, NULL, &error); + title16 = g_utf8_to_utf16(title ? title : "", + -1, NULL, NULL, &error); if (error != NULL) { debug_print("dialog title '%s' conversion to UTF-16 failed\n", title); g_error_free(error);