src: crash fixes

* fixed crash when snippet has no code.
* fixed crash when saving a filenode with special characters in its name
* fixed crash when aborting the parsing
This commit is contained in:
malte_langkabel
2016-05-20 13:52:37 +02:00
parent 946be38fa2
commit 4a6f8cf420
4 changed files with 36 additions and 5 deletions
+26 -3
View File
@@ -112,11 +112,14 @@ Id SqliteStorage::addNode(int type, const std::string& serializedName, int defin
);
Id id = m_database.lastRowId();
m_database.execDML((
CppSQLite3Statement stmt = m_database.compileStatement((
"INSERT INTO node(id, type, serialized_name, definition_type) VALUES("
+ std::to_string(id) + ", " + std::to_string(type) + ", '" + serializedName + "', " + std::to_string(definitionType) + ");"
+ std::to_string(id) + ", " + std::to_string(type) + ", ?, " + std::to_string(definitionType) + ");"
).c_str());
stmt.bind(1, serializedName.c_str());
stmt.execDML();
return id;
}
@@ -438,7 +441,27 @@ StorageNode SqliteStorage::getNodeById(Id id) const
StorageNode SqliteStorage::getNodeBySerializedName(const std::string& serializedName) const
{
return getFirst<StorageNode>("WHERE serialized_name == '" + serializedName + "'");
CppSQLite3Statement stmt = m_database.compileStatement(
"SELECT id, type, serialized_name, definition_type FROM node WHERE serialized_name == ? LIMIT 1;"
);
stmt.bind(1, serializedName.c_str());
CppSQLite3Query q = stmt.execQuery();
if (!q.eof())
{
const Id id = q.getIntField(0, 0);
const int type = q.getIntField(1, -1);
const std::string serializedName = q.getStringField(2, "");
const int definitionType = q.getIntField(3, 0);
if (id != 0 && type != -1)
{
return StorageNode(id, type, serializedName, definitionType);
}
}
return StorageNode();
}
std::vector<StorageNode> SqliteStorage::getNodesByIds(const std::vector<Id>& nodeIds) const
@@ -23,7 +23,7 @@ Task::TaskState TaskGroupParallel::update()
{
for (size_t i = 0; i < m_tasks.size(); i++)
{
std::thread(&TaskGroupParallel::processTask, this, m_tasks[i]).detach();
m_threads.push_back(std::thread(&TaskGroupParallel::processTask, this, m_tasks[i]));
std::lock_guard<std::mutex> lock(m_activeTaskCountMutex);
m_activeTaskCount++;
@@ -47,6 +47,11 @@ Task::TaskState TaskGroupParallel::update()
void TaskGroupParallel::exit()
{
for (size_t i = 0; i < m_threads.size(); i++)
{
m_threads[i].join();
}
m_threads.clear();
}
void TaskGroupParallel::interrupt()
@@ -23,6 +23,9 @@ private:
volatile bool m_interrupt;
bool m_running;
std::vector<std::thread> m_threads;
volatile int m_activeTaskCount;
std::mutex m_activeTaskCountMutex;
};
+1 -1
View File
@@ -110,7 +110,7 @@ QtCodeArea::QtCodeArea(
m_highlighter = new QtHighlighter(document());
std::string displayCode = m_code;
if (*displayCode.rbegin() == '\n')
if (!displayCode.empty() && *displayCode.rbegin() == '\n')
{
displayCode.pop_back();
}