Skip to content

Commit

Permalink
Merge pull request #1 from Ahuge/B001-ZoicBadRegex
Browse files Browse the repository at this point in the history
Fix crash when bad regex is evaluated.
  • Loading branch information
Ahuge authored Dec 17, 2016
2 parents eef33d9 + 06b66c0 commit 4e4b4fe
Showing 1 changed file with 40 additions and 34 deletions.
74 changes: 40 additions & 34 deletions RemoveChannels/RemoveChannels.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RemoveChannels.cpp
// Alex Hughes (2016)
// Version 1.00
// Version 1.01

/*
Remove channels from the input.
Expand Down Expand Up @@ -80,41 +80,47 @@ void RemoveChannels::_validate(bool for_real)
this->copy_info(); // Get context of the channels that this node knows.

ChannelMask inputChannels = this->input0().info().channels(); // Get all availible channels.
this->rgx.assign(this->_message); // Assign our text as a regular expression.

foreach(c, inputChannels)
{
const std::string channelName = getName(c); // String name of the channel so we can go begin and end on it.
std::smatch match; // Our capture.

if (this->operation) { // Keep matching channels

// Regex matching.
if (std::regex_search(channelName.begin(), channelName.end(), match, this->rgx))
{
this->info_.turn_on(c); //? Tells that channel to turn on.
}

else
{
// Doesn't match
this->info_.turn_off(c); //? Tells that channel to turn off.
}
}
else // Remove matching channels
{
// Regex matching.
if (std::regex_search(channelName.begin(), channelName.end(), match, this->rgx))
{
this->info_.turn_off(c); //? Tells that channel to turn off.
try {
this->rgx.assign(this->_message); // Assign our text as a regular expression.

foreach(c, inputChannels)
{
const std::string channelName = getName(c); // String name of the channel so we can go begin and end on it.
std::smatch match; // Our capture.

if (this->operation) { // Keep matching channels

// Regex matching.
if (std::regex_search(channelName.begin(), channelName.end(), match, this->rgx))
{
this->info_.turn_on(c); //? Tells that channel to turn on.
}

else
{
// Doesn't match
this->info_.turn_off(c); //? Tells that channel to turn off.
}
}

else
else // Remove matching channels
{
// Doesn't match
this->info_.turn_on(c); //? Tells that channel to turn on.
// Regex matching.
if (std::regex_search(channelName.begin(), channelName.end(), match, this->rgx))
{
this->info_.turn_off(c); //? Tells that channel to turn off.
}

else
{
// Doesn't match
this->info_.turn_on(c); //? Tells that channel to turn on.
}
}
}
}
}
catch (std::regex_error& e) {
// Syntax error in the regular expression
this->error("Syntax error in the regular expression.");
}
this->set_out_channels(channels); //? Tells nuke what we changed.
}
Expand All @@ -136,4 +142,4 @@ static Iop* build(Node* node)
// Build the node.
return new RemoveChannels(node);
}
Iop::Description RemoveChannels::description(CLASS, "Channel/RemoveChannels", build);
Iop::Description RemoveChannels::description(CLASS, "Channel/RemoveChannels", build);

0 comments on commit 4e4b4fe

Please sign in to comment.