After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 781095 - files-view: disable create-link when the clipboard is empty
files-view: disable create-link when the clipboard is empty
Status: RESOLVED FIXED
Product: nautilus
Classification: Core
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: Nautilus Maintainers
Nautilus Maintainers
Depends on:
Blocks:
 
 
Reported: 2017-04-09 11:14 UTC by Tiberiu Lepadatu
Modified: 2017-06-24 12:20 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
files-view: disable create-link when the clipboard is empty (2.36 KB, patch)
2017-04-09 11:15 UTC, Tiberiu Lepadatu
committed Details | Review
clipboard: remove duplicate function declaration (900 bytes, patch)
2017-06-24 12:18 UTC, Ernestas Kulik
committed Details | Review

Description Tiberiu Lepadatu 2017-04-09 11:14:57 UTC
See patch.
Comment 1 Tiberiu Lepadatu 2017-04-09 11:15:01 UTC
Created attachment 349553 [details] [review]
files-view: disable create-link when the clipboard is empty

'Create Link' button does nothing when the clipboard is empty. In order to fix
that, disable the button when the clipboard is empty.
Comment 2 Evgeny Shulgin 2017-04-12 17:08:18 UTC
I'm not a maintainer of Nautilus (just an enthusiast), but seems that 'selection_data == NULL' checking is redundant.

At least we have this call stack: on_clipboard_contents_received -> nautilus_clipboard_is_cut_from_selection_data -> get_item_list_from_selection_data -> gtk_selection_data_get_length (where 'selection_data' are without checking for NULL).
Comment 3 Ernestas Kulik 2017-04-12 17:14:05 UTC
(In reply to Evgeny Shulgin from comment #2)
> I'm not a maintainer of Nautilus (just an enthusiast), but seems that
> 'selection_data == NULL' checking is redundant.
> 
> At least we have this call stack: on_clipboard_contents_received ->
> nautilus_clipboard_is_cut_from_selection_data ->
> get_item_list_from_selection_data -> gtk_selection_data_get_length (where
> 'selection_data' are without checking for NULL).

So it would just crash with a null pointer.

For public API it’s just good practice to use g_return{,_val}_if_fail and check if the object is an instance of the type (which is not done here, but should be).
Comment 4 Ernestas Kulik 2017-04-12 17:17:35 UTC
And it does look redundant, yes. The docs, however, don’t mention that it allows null, so it’s also good to not pass null pointers to it (or fix the documentation).
Comment 5 Ernestas Kulik 2017-04-12 17:31:24 UTC
Review of attachment 349553 [details] [review]:

LGTM

::: src/nautilus-clipboard.h
@@ +37,3 @@
 gboolean
 nautilus_clipboard_is_cut_from_selection_data (GtkSelectionData *selection_data);
+gboolean nautilus_clipboard_is_selection_data_empty (GtkSelectionData *selection_data);

The parameter should be const-qualified, since we’re not modifying it (nor is gtk_selection_data_get_length ()).
Comment 6 Ernestas Kulik 2017-04-12 17:36:45 UTC
(In reply to Ernestas Kulik from comment #3 and #4)

I should just shut up.

The null check there is fine. We could require the pointer to be valid (as in gtk_selection_data_get_length () or just passing the pointer through) and get warnings for invalid invocations, but I don’t see a need. There either is something in the selection or not (or there is no selection at all).
Comment 7 Ernestas Kulik 2017-06-24 12:18:58 UTC
Created attachment 354384 [details] [review]
clipboard: remove duplicate function declaration
Comment 8 Ernestas Kulik 2017-06-24 12:20:21 UTC
Attachment 349553 [details] pushed as afe1384 - files-view: disable create-link when the clipboard is empty
Attachment 354384 [details] pushed as c472551 - clipboard: remove duplicate function declaration