Commit 019e6188 authored by Nikolai Kosjar's avatar Nikolai Kosjar

Clang: Fix removing unsaved file

We called delete[] on invalid data.

Change-Id: I94147c80119e27b42c280fb527966602fc456f8b
Reviewed-by: default avatarMarco Bubke <marco.bubke@theqtcompany.com>
parent ef7a7a44
......@@ -30,6 +30,7 @@
#include "unsavedfiles.h"
#include <algorithm>
#include <cstring>
namespace ClangBackEnd {
......@@ -154,12 +155,12 @@ void UnsavedFiles::updateCXUnsavedFileWithFileContainer(const FileContainer &fil
void UnsavedFiles::removeCXUnsavedFile(const FileContainer &fileContainer)
{
const Utf8String filePath = fileContainer.filePath();
auto removeBeginIterator = std::remove_if(d->cxUnsavedFiles.begin(),
auto removeBeginIterator = std::partition(d->cxUnsavedFiles.begin(),
d->cxUnsavedFiles.end(),
[filePath] (const CXUnsavedFile &cxUnsavedFile) { return filePath == cxUnsavedFile.Filename; });
[filePath] (const CXUnsavedFile &cxUnsavedFile) { return filePath != cxUnsavedFile.Filename; });
std::for_each(removeBeginIterator, d->cxUnsavedFiles.end(), UnsavedFiles::deleteCXUnsavedFile);
d->cxUnsavedFiles.erase( removeBeginIterator, d->cxUnsavedFiles.end());
d->cxUnsavedFiles.erase(removeBeginIterator, d->cxUnsavedFiles.end());
}
void UnsavedFiles::addOrUpdateCXUnsavedFile(const FileContainer &fileContainer)
......@@ -182,6 +183,4 @@ void UnsavedFiles::updateLastChangeTimePoint()
d->lastChangeTimePoint = std::chrono::steady_clock::now();
}
} // namespace ClangBackEnd
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