Skip to content

Commit

Permalink
viewer search crash fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Jul 3, 2016
1 parent 30ad9eb commit 0ff786e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
4 changes: 4 additions & 0 deletions far/changelog
@@ -1,3 +1,7 @@
drkns 03.07.2016 19:11:29 +0200 - build 4735

1. При определенных условиях мог падать поиск во вьювере.

drkns 03.07.2016 18:07:21 +0200 - build 4734

1. Рефакторинг.
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
@@ -1 +1 @@
m4_define(BUILD,4734)m4_dnl
m4_define(BUILD,4735)m4_dnl
16 changes: 8 additions & 8 deletions far/viewer.cpp
Expand Up @@ -2597,11 +2597,11 @@ intptr_t Viewer::ViewerSearchDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,vo
EditorSetPosition esp={sizeof(EditorSetPosition)};
esp.CurPos = -1;
Dlg->SendMessage(DM_GETEDITPOSITION, sd_src, &esp);
const wchar_t *ps = (const wchar_t *)Dlg->SendMessage(DM_GETCONSTTEXTPTR, sd_src, nullptr);
FarDialogItemData item = {sizeof(FarDialogItemData)};
Dlg->SendMessage(DM_GETTEXT, sd_src, &item);
const auto HexString = Dialog::ExtractHexString({ reinterpret_cast<const wchar_t*>(Dlg->SendMessage(DM_GETCONSTTEXTPTR, sd_src, nullptr)), item.PtrLength });
string strTo;
Data->viewer->SearchTextTransform(strTo, ps, item.PtrLength, !new_hex, esp.CurPos);
Data->viewer->SearchTextTransform(strTo, HexString, !new_hex, esp.CurPos);
item.PtrLength = strTo.size();
item.PtrData = UNSAFE_CSTR(strTo);
Dlg->SendMessage(DM_SETTEXT, sd_dst, &item);
Expand Down Expand Up @@ -2714,20 +2714,20 @@ void ViewerSearchMsg(const string& MsgStr, int Percent, int SearchHex)
}
}

static auto hex2ss(const wchar_t *from, size_t len, intptr_t *pos = nullptr)
static auto hex2ss(const string& from, intptr_t *pos = nullptr)
{
string strFrom(from, len);
string strFrom(from);
RemoveTrailingSpaces(strFrom);
if (pos)
*pos /= 2;
return HexStringToBlob(strFrom.data(), 0);
}

void Viewer::SearchTextTransform(string &to, const wchar_t *from, size_t from_len, bool hex2text, intptr_t &pos)
void Viewer::SearchTextTransform(string &to, const string& from, bool hex2text, intptr_t &pos)
{
if (hex2text)
{
auto Bytes = hex2ss(from, from_len, &pos);
auto Bytes = hex2ss(from, &pos);
if (IsUnicodeCodePage(m_Codepage))
{
int v = CP_REVERSEBOM == m_Codepage ? 1 : 0;
Expand Down Expand Up @@ -2756,7 +2756,7 @@ void Viewer::SearchTextTransform(string &to, const wchar_t *from, size_t from_le
char Buffer[128];
size_t Size;
int ps = 0, pd = 0, p0 = pos, p1 = -1;
for (size_t i=0; i < from_len; ++i)
for (size_t i = 0, FromSize = from.size(); i != FromSize; ++i)
{
if (ps == p0)
p1 = pd;
Expand Down Expand Up @@ -3446,7 +3446,7 @@ void Viewer::Search(int Next,int FirstChar)
sd.search_len = (int)strSearchStr.size();
if (true == (LastSearchHex = SearchHex))
{
search_bytes = hex2ss(strSearchStr.data(), strSearchStr.size());
search_bytes = hex2ss(strSearchStr);
sd.search_len = (int)search_bytes.size();
sd.search_bytes = search_bytes.data();
sd.ch_size = 1;
Expand Down
2 changes: 1 addition & 1 deletion far/viewer.hpp
Expand Up @@ -91,7 +91,7 @@ class Viewer:public SimpleScreenObject
bool ProcessDisplayMode(VIEWER_MODE_TYPE newMode, bool isRedraw = true);
int ProcessWrapMode(int newMode, bool isRedraw = true);
int ProcessTypeWrapMode(int newMode, bool isRedraw = true);
void SearchTextTransform(string& to, const wchar_t *from, size_t from_len, bool hex2text, intptr_t &pos);
void SearchTextTransform(string& to, const string& from, bool hex2text, intptr_t &pos);
int GetId(void) const { return ViewerID; }
void OnDestroy(void);

Expand Down

0 comments on commit 0ff786e

Please sign in to comment.