Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quick fix for crash on the start of line regex #459

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions src/SearchDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3890,23 +3890,24 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
bLoadResult = textFile.Load(sInfo.filePath.c_str(), type, m_bUTF8, bCancelled);
}
sInfo.encoding = type;

int ft = boost::regex::normal;
if (!bCaseSensitive)
ft |= boost::regbase::icase;
boost::match_flag_type flags = boost::match_default | boost::format_all;
if (!bDotMatchesNewline)
flags |= boost::match_not_dot_newline;

if ((bLoadResult) && ((type != CTextFile::Binary) || (bIncludeBinary) || bSearchAlways))
{
sInfo.readError = false;
std::wstring::const_iterator start, end;
start = textFile.GetFileString().begin();
end = textFile.GetFileString().end();
boost::match_results<std::wstring::const_iterator> what;
try
{
int ft = boost::regex::normal;
if (!bCaseSensitive)
ft |= boost::regbase::icase;
boost::wregex expression = boost::wregex(localSearchString, ft);
boost::match_results<std::wstring::const_iterator> whatC;
boost::match_flag_type flags = boost::match_default | boost::format_all;
if (!bDotMatchesNewline)
flags |= boost::match_not_dot_newline;
while (!bCancelled && regex_search(start, end, whatC, expression, flags))
{
if (whatC[0].matched)
Expand Down Expand Up @@ -3961,7 +3962,7 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
flags |= boost::match_prev_avail;
flags |= boost::match_not_bob;
}
if (type == CTextFile::Binary)
if (nFound == 0 && type == CTextFile::Binary)
{
boost::wregex expressionUtf16 = boost::wregex(searchStringUtf16Le, ft);
start = textFile.GetFileString().begin();
Expand Down Expand Up @@ -4158,14 +4159,6 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
searchFor += "\\E";
}

boost::match_results<std::string::const_iterator> what;
boost::match_flag_type flags = boost::match_default | boost::format_all;
if (!bDotMatchesNewline)
flags |= boost::match_not_dot_newline;
int ft = boost::regex::normal;
if (!bCaseSensitive)
ft |= boost::regbase::icase;

try
{
boost::regex expression = boost::regex(searchFor, ft);
Expand Down Expand Up @@ -4199,7 +4192,7 @@ void CSearchDlg::SearchFile(CSearchInfo sInfo, const std::wstring& searchRoot, b
break;
}
}
if (type == CTextFile::Binary && !m_bReplace)
if (nFound == 0 && type == CTextFile::Binary && !m_bReplace)
{
boost::wregex expressionUtf16Le = boost::wregex(searchString, ft);
boost::spirit::classic::file_iterator<wchar_t> start(filePath.c_str());
Expand Down