diff options
author | Jaap Keuter <jaap.keuter@xs4all.nl> | 2012-09-22 23:47:23 +0000 |
---|---|---|
committer | Jaap Keuter <jaap.keuter@xs4all.nl> | 2012-09-22 23:47:23 +0000 |
commit | 37b6ca2ce8ba54810f54f86c5c17170315ccd0eb (patch) | |
tree | fb051ee40edbc3f3f9e1cedff470d4acbda8ca0c /ui/gtk/drag_and_drop.c | |
parent | 1a3d5f03f3e3728c39d70b2364ff9d3db739d79b (diff) |
Fix for bug 7744:
Have the DND data receiver make sure that the URI-list is always correctly terminated. Do so for any source, either X server, Windows or OS X.
svn path=/trunk/; revision=45058
Diffstat (limited to 'ui/gtk/drag_and_drop.c')
-rw-r--r-- | ui/gtk/drag_and_drop.c | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/ui/gtk/drag_and_drop.c b/ui/gtk/drag_and_drop.c index daf2defaa3..961deb26e8 100644 --- a/ui/gtk/drag_and_drop.c +++ b/ui/gtk/drag_and_drop.c @@ -213,9 +213,9 @@ dnd_open_file_cmd(gchar *cf_names_freeme) char **in_filenames; - /* DND_TARGET_URL on Win32: + /* DND_TARGET_URL: * The cf_name_freeme is a single string, containing one or more URI's, - * seperated by CR/NL chars. The length of the whole field can be found + * terminated by CR/NL chars. The length of the whole field can be found * in the selection_data->length field. If it contains one file, simply open it, * If it contains more than one file, ask to merge these files. */ @@ -249,6 +249,7 @@ dnd_open_file_cmd(gchar *cf_names_freeme) switch(in_files) { case(0): /* shouldn't happen */ + g_error("Drag and drop to open file, but no filenames? (%s)", cf_name ? cf_name : "null"); break; case(1): /* open and read the capture file (this will close an existing file) */ @@ -322,18 +323,22 @@ dnd_data_received(GtkWidget *widget _U_, GdkDragContext *dc _U_, gint x _U_, gin return; } - /* the selection_data will soon be gone, make a copy first */ - /* the data string is not zero terminated -> make a zero terminated "copy" of it */ - sel_data_len = gtk_selection_data_get_length(selection_data); - sel_data_data = gtk_selection_data_get_data(selection_data); - cf_names_freeme = g_malloc(sel_data_len + 1); - memcpy(cf_names_freeme, sel_data_data, sel_data_len); - cf_names_freeme[sel_data_len] = '\0'; - + /* the selection_data will soon be gone, make a copy first */ + /* the data string is not zero terminated -> make a zero terminated "copy" of it */ + sel_data_len = gtk_selection_data_get_length(selection_data); + sel_data_data = gtk_selection_data_get_data(selection_data); + cf_names_freeme = g_malloc(sel_data_len + 3); + memcpy(cf_names_freeme, sel_data_data, sel_data_len); + if (cf_names_freeme[sel_data_len - 1] != '\n') { + cf_names_freeme[sel_data_len++] = '\r'; + cf_names_freeme[sel_data_len++] = '\n'; + } + cf_names_freeme[sel_data_len] = '\0'; + /* If there's unsaved data, let the user save it first. If they cancel out of it, don't open the file. */ if (do_file_close(&cfile, FALSE, " before opening a new capture file")) - dnd_open_file_cmd( cf_names_freeme ); + dnd_open_file_cmd(cf_names_freeme); } } @@ -342,21 +347,11 @@ gboolean gtk_osx_openFile (GtkOSXApplication *app _U_, gchar *path, gpointer user_data _U_) { GtkSelectionData selection_data; - gchar *selection_path; - int length = strlen(path) + 3; - - selection_path = g_malloc(length + 3); - memcpy(selection_path, path, length); - - selection_path[length] = '\r'; - selection_path[length + 1] = '\n'; - selection_path[length + 2] = '\0'; - - gtk_selection_data_set_text(&selection_data, selection_path, length); + int length = strlen(path); + + gtk_selection_data_set_text(&selection_data, path, length); dnd_data_received(NULL, NULL, 0, 0, &selection_data, DND_TARGET_URL, 0, 0); - g_free(selection_path); - return TRUE; } #endif |