[gnome-commander/gcmd-1-12: 1/2] set_fs_directory_to_opposite: Fix segv when no directory is chosen
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander/gcmd-1-12: 1/2] set_fs_directory_to_opposite: Fix segv when no directory is chosen
- Date: Tue, 11 May 2021 19:35:17 +0000 (UTC)
commit d8c97aade32c7146ea4c24880476bf2dc6d05baf
Author: Mamoru TASAKA <mtasaka fedoraproject org>
Date: Wed May 12 00:34:45 2021 +0900
set_fs_directory_to_opposite: Fix segv when no directory is chosen
When doing CTRL+LEFT or CTRL+RIGHT, "GnomeCmdMainWin::set_fs_directory_to_opposite" is executed.
When a file list is chosen and active, set_fs_directory_to_opposite try to set the opposite
directory to the chosen list.
However, when no file is chosen and any file list is inactive, get_selected_file() returns nullptr,
this leads file->GetGfileAttributeUInt32() segfault.
(Note that with optimization, even if file is nullptr, file->GetGfileAttributeUInt32() will be
usually called, because compiler guesses file cannot be null when compilation.
But in file->GetGfileAttributeUInt32(), this->gFile is accessed, which causes segfault anyway.)
To fix this, check if get_selected_file() returned non-null pointer or not (i.e.
some file list is active or not.)
src/gnome-cmd-main-win.cc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
---
diff --git a/src/gnome-cmd-main-win.cc b/src/gnome-cmd-main-win.cc
index 783b1da2..0d024754 100644
--- a/src/gnome-cmd-main-win.cc
+++ b/src/gnome-cmd-main-win.cc
@@ -1253,7 +1253,7 @@ void GnomeCmdMainWin::set_fs_directory_to_opposite(FileSelectorID fsID)
{
GnomeCmdFile *file = other->file_list()->get_selected_file();
- if (file->GetGfileAttributeUInt32(G_FILE_ATTRIBUTE_STANDARD_TYPE) == G_FILE_TYPE_DIRECTORY)
+ if (file && (file->GetGfileAttributeUInt32(G_FILE_ATTRIBUTE_STANDARD_TYPE) == G_FILE_TYPE_DIRECTORY))
dir = GNOME_CMD_IS_DIR (file) ? GNOME_CMD_DIR (file) : gnome_cmd_dir_new_from_info (file->info,
dir);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]