Skip to content

Commit

Permalink
Fix potential exit crash, DN_DRAWDLGITEM correction
Browse files Browse the repository at this point in the history
1. Fix a potential crash at exit.
2. Continue 5845.6 - do not populate FarDialogItem.ListItems in DN_DRAWDLGITEM.
  • Loading branch information
alabuzhev committed Jul 29, 2021
1 parent 0c68e95 commit a00819b
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 21 deletions.
7 changes: 7 additions & 0 deletions far/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
--------------------------------------------------------------------------------
drkns 29.07.2021 19:41:27 +0100 - build 5859

1. Fix a potential crash at exit.

2. Continue 5845.6 - do not populate FarDialogItem.ListItems in DN_DRAWDLGITEM.

--------------------------------------------------------------------------------
drkns 26.07.2021 17:27:54 +0100 - build 5858

Expand Down
1 change: 1 addition & 0 deletions far/common/preprocessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Type& operator=(Type&&) = delete

#define MOVABLE(Type) \
~Type() = default; \
MOVE_CONSTRUCTIBLE(Type); \
MOVE_ASSIGNABLE(Type)

Expand Down
46 changes: 29 additions & 17 deletions far/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ static size_t ConvertItemEx2(const DialogItemEx *ItemEx, FarGetDialogItem *Item,
auto offsetListItems = size;
vmenu_ptr ListBox;
size_t ListBoxSize = 0;
if (ConvertListbox && (ItemEx->Type==DI_LISTBOX || ItemEx->Type==DI_COMBOBOX))

const auto IsList = ItemEx->Type == DI_LISTBOX || ItemEx->Type == DI_COMBOBOX;

if (IsList && ConvertListbox)
{
ListBox=ItemEx->ListPtr;
if (ListBox)
Expand All @@ -230,26 +233,35 @@ static size_t ConvertItemEx2(const DialogItemEx *ItemEx, FarGetDialogItem *Item,
if(Item->Item && Item->Size >= size)
{
ConvertItemSmall(*ItemEx, *Item->Item);
if (ListBox)

if (IsList)
{
const auto list = static_cast<FarList*>(static_cast<void*>(reinterpret_cast<char*>(Item->Item) + offsetList));
const auto listItems = static_cast<FarListItem*>(static_cast<void*>(reinterpret_cast<char*>(Item->Item) + offsetListItems));
auto text = static_cast<wchar_t*>(static_cast<void*>(listItems + ListBoxSize));
for(size_t ii = 0; ii != ListBoxSize; ++ii)
if (ConvertListbox)
{
auto& item = ListBox->at(ii);
listItems[ii].Flags=item.Flags;
listItems[ii].Text=text;
text += item.Name.copy(text, item.Name.npos);
*text++ = {};
listItems[ii].UserData = item.SimpleUserData;
listItems[ii].Reserved = 0;
const auto list = static_cast<FarList*>(static_cast<void*>(reinterpret_cast<char*>(Item->Item) + offsetList));
const auto listItems = static_cast<FarListItem*>(static_cast<void*>(reinterpret_cast<char*>(Item->Item) + offsetListItems));
auto text = static_cast<wchar_t*>(static_cast<void*>(listItems + ListBoxSize));
for (size_t ii = 0; ii != ListBoxSize; ++ii)
{
auto& item = ListBox->at(ii);
listItems[ii].Flags = item.Flags;
listItems[ii].Text = text;
text += item.Name.copy(text, item.Name.npos);
*text++ = {};
listItems[ii].UserData = item.SimpleUserData;
listItems[ii].Reserved = 0;
}
list->StructSize = sizeof(*list);
list->ItemsNumber = ListBoxSize;
list->Items = listItems;
Item->Item->ListItems = list;
}
else
{
Item->Item->ListItems = {};
}
list->StructSize=sizeof(*list);
list->ItemsNumber=ListBoxSize;
list->Items=listItems;
Item->Item->ListItems=list;
}

auto p = static_cast<wchar_t*>(static_cast<void*>(reinterpret_cast<char*>(Item->Item) + offsetStrings));
Item->Item->Data = p;
p += str.copy(p, str.npos);
Expand Down
2 changes: 1 addition & 1 deletion far/far.natvis
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<CustomListItems>
<Variable Name="i" InitialValue="0"/>
<Loop>
<Item Name="row[{i}]">m_Data + i * m_Rows,[m_Cols]na</Item>
<Item Name="row[{i}]">m_Data + i * m_Cols,[m_Cols]na</Item>
<Exec>++i</Exec>
<If Condition="i == m_Rows">
<Break/>
Expand Down
13 changes: 13 additions & 0 deletions far/filelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,19 @@ FileList::~FileList()
}


FileList::list_data& FileList::list_data::operator=(FileList::list_data&& rhs)
{
clear();

Items = std::move(rhs.Items);
rhs.Items.clear();

m_Plugin = std::move(rhs.m_Plugin);
rhs.m_Plugin = {};

return *this;
}

void FileList::list_data::clear()
{
for (auto& i: Items)
Expand Down
4 changes: 3 additions & 1 deletion far/filelist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,15 @@ class FileList:public Panel
{
public:
NONCOPYABLE(list_data);
MOVABLE(list_data);
MOVE_CONSTRUCTIBLE(list_data);

using value_type = FileListItem;

list_data() = default;
~list_data() { clear(); }

list_data& operator=(list_data&& rhs);

void initialise(plugin_panel* ph) { clear(); m_Plugin = ph; }

void clear();
Expand Down
20 changes: 20 additions & 0 deletions far/platform.concurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ namespace os::concurrency


thread::~thread()
{
finalise();
}

void thread::finalise()
{
if (!joinable())
return;
Expand All @@ -102,6 +107,21 @@ namespace os::concurrency
}
}

thread& thread::operator=(thread&& rhs)
{
finalise();

handle::operator=(std::move(rhs));

m_Mode = rhs.m_Mode;
rhs.m_Mode = {};

m_ThreadId = rhs.m_ThreadId;
rhs.m_ThreadId = {};

return *this;
}

unsigned thread::get_id() const
{
return m_ThreadId;
Expand Down
5 changes: 4 additions & 1 deletion far/platform.concurrency.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace os::concurrency
{
public:
NONCOPYABLE(thread);
MOVABLE(thread);
MOVE_CONSTRUCTIBLE(thread);

enum class mode
{
Expand All @@ -102,6 +102,8 @@ namespace os::concurrency

~thread();

thread& operator=(thread&& rhs);

[[nodiscard]]
unsigned get_id() const;

Expand All @@ -113,6 +115,7 @@ namespace os::concurrency

private:
void check_joinable() const;
void finalise();

template<class T>
void starter(T&& f)
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5858
5859

0 comments on commit a00819b

Please sign in to comment.