Skip to content

Commit

Permalink
Prevent crashes with invalid addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Sep 4, 2015
1 parent cf2ec31 commit c99d497
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 12 deletions.
1 change: 1 addition & 0 deletions base/lib/iscore/tools/TreeNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class TreeNode : public DataType
static_cast<DataType&>(*this) = static_cast<const DataType&>(source);

qDeleteAll(m_children);
m_children.clear();
for(const auto& child : source.children())
{
this->addChild(new TreeNode{*child, this});
Expand Down
8 changes: 8 additions & 0 deletions base/plugins/iscore-lib-state/State/Expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ struct ExprData : public VariantBasedNode<Relation, BinaryOperator, UnaryOperato

}
using iscore::ExprData;

template<>
/**
* @brief The TreeNode<ExprData> class
*
* This class is specialized from TreeNode<T>
* because we want to have an additional check :
* a node is a leaf iff a node is a iscore::Relation
*/
class TreeNode<ExprData> : public ExprData
{
ISCORE_SERIALIZE_FRIENDS(TreeNode<ExprData>, DataStream)
Expand Down
16 changes: 8 additions & 8 deletions base/plugins/iscore-lib-state/State/ExpressionSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,28 @@ template<> class TypeToName<iscore::UnaryOperator>


template<>
void Visitor<Reader<DataStream>>::readFrom(const ExprData& state)
void Visitor<Reader<DataStream>>::readFrom(const ExprData& expr)
{
readFrom(state.m_data);
readFrom(expr.m_data);
insertDelimiter();
}

template<>
void Visitor<Reader<JSONObject>>::readFrom(const ExprData& state)
void Visitor<Reader<JSONObject>>::readFrom(const ExprData& expr)
{
readFrom(state.m_data);
readFrom(expr.m_data);
}

template<>
void Visitor<Writer<DataStream>>::writeTo(ExprData& state)
void Visitor<Writer<DataStream>>::writeTo(ExprData& expr)
{
writeTo(state.m_data);
writeTo(expr.m_data);
checkDelimiter();
}

template<>
void Visitor<Writer<JSONObject>>::writeTo(ExprData& state)
void Visitor<Writer<JSONObject>>::writeTo(ExprData& expr)
{
writeTo(state.m_data);
writeTo(expr.m_data);
}

Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,15 @@ void OSSIAScenarioElement::on_eventCreated(const EventModel& const_ev)

connect(&ev, &EventModel::conditionChanged,
this, [=] (const iscore::Condition& c) {
ossia_ev->setExpression(iscore::convert::expression(c, m_deviceList));
try {
auto expr = iscore::convert::expression(c, m_deviceList);

ossia_ev->setExpression(expr);
}
catch(std::exception& e)
{
qDebug() << e.what();
}
});

// Create the mapping object
Expand Down
29 changes: 26 additions & 3 deletions base/plugins/iscore-plugin-ossia/iscore2OSSIA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,25 @@

#include "Protocols/OSSIADevice.hpp"
#include <QMap>


class NodeNotFoundException : public std::exception
{
const iscore::Address& m_addr;
public:
NodeNotFoundException(const iscore::Address& n):
m_addr{n}
{

}

const char* what() const noexcept override
{
return QString("Address: %1 not found in actual tree.")
.arg(m_addr.toString()).toLatin1().constData();
}
};

namespace iscore
{
namespace convert
Expand Down Expand Up @@ -372,6 +391,8 @@ std::shared_ptr<OSSIA::State> state(
return ossia_state;
}



OSSIA::Value* expressionOperand(
const iscore::RelationMember& relm,
const DeviceList& devlist)
Expand All @@ -383,7 +404,9 @@ OSSIA::Value* expressionOperand(
{
const auto& addr = get<iscore::Address>(relm);
if(!devlist.hasDevice(addr.device))
return nullptr;
{
throw NodeNotFoundException(addr);
}

auto& device = devlist.device(addr.device);

Expand All @@ -396,12 +419,12 @@ OSSIA::Value* expressionOperand(
}
else
{
return nullptr;
throw NodeNotFoundException(addr);
}
}
else
{
return nullptr;
throw NodeNotFoundException(addr);
}

break;
Expand Down

0 comments on commit c99d497

Please sign in to comment.