Skip to content

Commit 21f91a1

Browse files
committed
quick fix for crash on the start of line regex
* the 1st try has set flag `boost::match_prev_avail` * the 2 tries does not work for Replace at the same time, currently
1 parent fc383f4 commit 21f91a1

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

src/SearchDlg.cpp

+10-17
Original file line numberDiff line numberDiff line change
@@ -3890,23 +3890,24 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
38903890
bLoadResult = textFile.Load(sInfo.filePath.c_str(), type, m_bUTF8, bCancelled);
38913891
}
38923892
sInfo.encoding = type;
3893+
3894+
int ft = boost::regex::normal;
3895+
if (!bCaseSensitive)
3896+
ft |= boost::regbase::icase;
3897+
boost::match_flag_type flags = boost::match_default | boost::format_all;
3898+
if (!bDotMatchesNewline)
3899+
flags |= boost::match_not_dot_newline;
3900+
38933901
if ((bLoadResult) && ((type != CTextFile::Binary) || (bIncludeBinary) || bSearchAlways))
38943902
{
38953903
sInfo.readError = false;
38963904
std::wstring::const_iterator start, end;
38973905
start = textFile.GetFileString().begin();
38983906
end = textFile.GetFileString().end();
3899-
boost::match_results<std::wstring::const_iterator> what;
39003907
try
39013908
{
3902-
int ft = boost::regex::normal;
3903-
if (!bCaseSensitive)
3904-
ft |= boost::regbase::icase;
39053909
boost::wregex expression = boost::wregex(localSearchString, ft);
39063910
boost::match_results<std::wstring::const_iterator> whatC;
3907-
boost::match_flag_type flags = boost::match_default | boost::format_all;
3908-
if (!bDotMatchesNewline)
3909-
flags |= boost::match_not_dot_newline;
39103911
while (!bCancelled && regex_search(start, end, whatC, expression, flags))
39113912
{
39123913
if (whatC[0].matched)
@@ -3961,7 +3962,7 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
39613962
flags |= boost::match_prev_avail;
39623963
flags |= boost::match_not_bob;
39633964
}
3964-
if (type == CTextFile::Binary)
3965+
if (nFound == 0 && type == CTextFile::Binary)
39653966
{
39663967
boost::wregex expressionUtf16 = boost::wregex(searchStringUtf16Le, ft);
39673968
start = textFile.GetFileString().begin();
@@ -4158,14 +4159,6 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
41584159
searchFor += "\\E";
41594160
}
41604161

4161-
boost::match_results<std::string::const_iterator> what;
4162-
boost::match_flag_type flags = boost::match_default | boost::format_all;
4163-
if (!bDotMatchesNewline)
4164-
flags |= boost::match_not_dot_newline;
4165-
int ft = boost::regex::normal;
4166-
if (!bCaseSensitive)
4167-
ft |= boost::regbase::icase;
4168-
41694162
try
41704163
{
41714164
boost::regex expression = boost::regex(searchFor, ft);
@@ -4199,7 +4192,7 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
41994192
break;
42004193
}
42014194
}
4202-
if (type == CTextFile::Binary && !m_bReplace)
4195+
if (nFound == 0 && type == CTextFile::Binary && !m_bReplace)
42034196
{
42044197
boost::wregex expressionUtf16Le = boost::wregex(searchString, ft);
42054198
boost::spirit::classic::file_iterator<wchar_t> start(filePath.c_str());

0 commit comments

Comments
 (0)