Commit 18c8b7d5 authored by Oleg Solovyov's avatar Oleg Solovyov 🐴 Committed by Albert Astals Cid
Browse files

Fix stack overflow

We get an infinite recursion when we perform search with no files found.
See below:

void FileSearchTab::performSearch()
{
    if (m_searchFileListView->files().isEmpty()) { // <= assume true
        addFilesToSearch(doScanRecursive(QDir(Project::instance()->poDir()))); // <= arg is an empty list
	if (m_searchFileListView->files().isEmpty()) // <= unreachable, see below
	[...]
}

void FileSearchTab::addFilesToSearch(const QStringList& files)
{
    m_searchFileListView->addFiles(files); // <= files.isEmpty() == true
    performSearch(); // <= m_searchFileListView->files().isEmpty() == true
}

Steps to reproduce:
1) Project -> Create software translation project -> Save
2) RMB -> Search in files
3) Wait ~1 minute until crash

(cherry picked from commit 9b82f864)
parent 5130ecf6
......@@ -544,9 +544,13 @@ FileSearchTab::~FileSearchTab()
void FileSearchTab::performSearch()
{
if (m_searchFileListView->files().isEmpty()) {
addFilesToSearch(doScanRecursive(QDir(Project::instance()->poDir())));
if (m_searchFileListView->files().isEmpty())
QStringList files = doScanRecursive(QDir(Project::instance()->poDir()));
// otherwise we will get stack overflow
if (files.isEmpty())
return;
addFilesToSearch(files);
}
m_model->clear();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment