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 773150 - Segfault on pressing Enter/activate in list view with nothing selected
Segfault on pressing Enter/activate in list view with nothing selected
Status: RESOLVED FIXED
Product: nautilus
Classification: Core
Component: Crashers
3.22.x
Other Linux
: Normal normal
: ---
Assigned To: Nautilus Maintainers
Nautilus Maintainers
: 773699 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2016-10-18 11:05 UTC by Daniel Boles
Modified: 2016-10-30 14:46 UTC
See Also:
GNOME target: ---
GNOME version: 3.21/3.22


Attachments
list-view: do not try to activate a NULL selection (1.17 KB, patch)
2016-10-18 11:10 UTC, Daniel Boles
none Details | Review
list-view: do not try to activate a NULL selection (1.39 KB, patch)
2016-10-18 12:52 UTC, Daniel Boles
committed Details | Review

Description Daniel Boles 2016-10-18 11:05:18 UTC
Open Nautilus in list view, then press the right arrow to move focus from the sidebar to the list view, but without selecting any items. Now press Enter. Nautilus tries to activate the selected items, but there are none, so it bails with a segfault. Backtrace:

Thread 1 "nautilus" received signal SIGSEGV, Segmentation fault.
0x0000000000490e43 in nautilus_files_view_activate_files (view=0xa571c0, files=files@entry=0x0, 
    flags=flags@entry=(unknown: 0), confirm_multiple=confirm_multiple@entry=1) at nautilus-files-view.c:1176
1176	        location = nautilus_file_get_location (NAUTILUS_FILE (g_list_first (files)->data));
(gdb) bt
  • #0 nautilus_files_view_activate_files
  • #1 activate_selected_items
    at nautilus-list-view.c line 231
  • #2 key_press_callback
    at nautilus-list-view.c line 1016
  • #3 ??
    from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
  • #4 g_closure_invoke
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #5 ??
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #6 g_signal_emit_valist
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #7 g_signal_emit
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #8 ??
    from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
  • #9 gtk_window_propagate_key_event
    from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
  • #10 ??
    from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
  • #11 nautilus_window_key_press_event
    at nautilus-window.c line 2543
  • #12 ??
    from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
  • #13 ??
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #14 g_signal_emit_valist
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #15 g_signal_emit
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #16 ??
    from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
  • #17 ??
    from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
  • #18 gtk_main_do_event
    from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
  • #19 ??
    from /usr/lib/x86_64-linux-gnu/libgdk-3.so.0
  • #20 ??
    from /usr/lib/x86_64-linux-gnu/libgdk-3.so.0
  • #21 g_main_context_dispatch
    from /lib/x86_64-linux-gnu/libglib-2.0.so.0
  • #22 ??
    from /lib/x86_64-linux-gnu/libglib-2.0.so.0
  • #23 g_main_context_iteration
    from /lib/x86_64-linux-gnu/libglib-2.0.so.0
  • #24 g_application_run
    from /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0
  • #25 main
    at nautilus-main.c line 102

Comment 1 Daniel Boles 2016-10-18 11:10:56 UTC
Created attachment 337934 [details] [review]
list-view: do not try to activate a NULL selection

Only try to activate if the list of selected items is non-NULL.
Comment 2 Ernestas Kulik 2016-10-18 11:47:41 UTC
Review of attachment 337934 [details] [review]:

Nice catch, thanks. Time for me to pick some nits, now. :)

It would be great if you could write something in the body of the commit message as well.
A short description of the issue will do.

::: src/nautilus-list-view.c
@@ +230,2 @@
     file_list = nautilus_list_view_get_selection (NAUTILUS_FILES_VIEW (view));
+    if (file_list)

For the sake of being explicit, change this to “file_list != NULL”.
IIRC, it is all over the place right now, but I try to do this more often.
Comment 3 Daniel Boles 2016-10-18 12:39:31 UTC
Thanks, will do.

Before that - in cases like this, is it OK to combine a variable's declaration and assignment on the same line? I see it done sometimes, but not usually. Is there a particular rule for when this can be done?
Comment 4 Daniel Boles 2016-10-18 12:52:02 UTC
Created attachment 337940 [details] [review]
list-view: do not try to activate a NULL selection

> It is possible to give focus to the list view with nothing selected. On
> pressing Enter, Nautilus would try to activate a null list of items and
> therefore segfault. Fix this by doing nothing if there is no selection.

This also adds the explicit comparison to NULL as requested by Ernestas.

(Following my previous comment, I'm assuming you want the variable declaration kept separate, as it originally was, and like most other code in the project.)
Comment 5 Ernestas Kulik 2016-10-18 12:53:36 UTC
(In reply to djb from comment #3)
> Thanks, will do.
> 
> Before that - in cases like this, is it OK to combine a variable's
> declaration and assignment on the same line? I see it done sometimes, but
> not usually. Is there a particular rule for when this can be done?

Hard to say, really. I do not think we have reached a consensus there. For one, it helps keep lines short and sweet (we have a soft limit of 80 characters and a hard one of 100), but it also inflates the line count.

It is best if you follow the style of existing code, but I will not bat an eyelid if you choose one over the other in your code, personally.
Comment 6 Ernestas Kulik 2016-10-18 12:56:20 UTC
(In reply to Ernestas Kulik from comment #5)
> it helps keep lines short and sweet

Err, not doing so, I mean.
Comment 7 Ernestas Kulik 2016-10-18 13:06:02 UTC
Review of attachment 337940 [details] [review]:

Sure, looks fine to me!
Comment 8 Ernestas Kulik 2016-10-18 13:06:48 UTC
Attachment 337940 [details] pushed as 9fa6a1f - list-view: do not try to activate a NULL selection
Comment 9 Ernestas Kulik 2016-10-30 14:46:19 UTC
*** Bug 773699 has been marked as a duplicate of this bug. ***