Skip to content

Commit

Permalink
fix: prevent modulo zero
Browse files Browse the repository at this point in the history
  • Loading branch information
midouest committed Feb 27, 2021
1 parent dabe980 commit fca5654
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions include/expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace bb

int evaluate(int t) const
{
return this->left->evaluate(t) + this->right->evaluate(t);
return left->evaluate(t) + right->evaluate(t);
};

protected:
Expand All @@ -91,7 +91,7 @@ namespace bb

int evaluate(int t) const
{
return this->left->evaluate(t) - this->right->evaluate(t);
return left->evaluate(t) - right->evaluate(t);
};

protected:
Expand All @@ -108,7 +108,7 @@ namespace bb

int evaluate(int t) const
{
return this->left->evaluate(t) * this->right->evaluate(t);
return left->evaluate(t) * right->evaluate(t);
};

protected:
Expand All @@ -125,13 +125,13 @@ namespace bb

int evaluate(int t) const
{
int divisor = this->right->evaluate(t);
int divisor = right->evaluate(t);
// Dividing by zero will crash the SuperCollider server
if (divisor == 0)
{
return 0;
}
return this->left->evaluate(t) / divisor;
return left->evaluate(t) / divisor;
};

protected:
Expand All @@ -148,7 +148,14 @@ namespace bb

int evaluate(int t) const
{
return this->left->evaluate(t) % this->right->evaluate(t);

int divisor = right->evaluate(t);
// Dividing by zero will crash the SuperCollider server
if (divisor == 0)
{
return 0;
}
return left->evaluate(t) % divisor;
};

protected:
Expand All @@ -165,7 +172,7 @@ namespace bb

int evaluate(int t) const
{
return this->left->evaluate(t) & this->right->evaluate(t);
return left->evaluate(t) & right->evaluate(t);
};

protected:
Expand All @@ -182,7 +189,7 @@ namespace bb

int evaluate(int t) const
{
return this->left->evaluate(t) | this->right->evaluate(t);
return left->evaluate(t) | right->evaluate(t);
};

protected:
Expand All @@ -199,7 +206,7 @@ namespace bb

int evaluate(int t) const
{
return this->left->evaluate(t) ^ this->right->evaluate(t);
return left->evaluate(t) ^ right->evaluate(t);
};

protected:
Expand All @@ -216,7 +223,7 @@ namespace bb

int evaluate(int t) const
{
return this->left->evaluate(t) << this->right->evaluate(t);
return left->evaluate(t) << right->evaluate(t);
};

protected:
Expand All @@ -233,7 +240,7 @@ namespace bb

int evaluate(int t) const
{
return this->left->evaluate(t) >> this->right->evaluate(t);
return left->evaluate(t) >> right->evaluate(t);
};

protected:
Expand All @@ -250,7 +257,7 @@ namespace bb

int evaluate(int t) const
{
return this->left->evaluate(t) < this->right->evaluate(t);
return left->evaluate(t) < right->evaluate(t);
};

protected:
Expand All @@ -267,7 +274,7 @@ namespace bb

int evaluate(int t) const
{
return this->left->evaluate(t) > this->right->evaluate(t);
return left->evaluate(t) > right->evaluate(t);
};

protected:
Expand All @@ -284,7 +291,7 @@ namespace bb

int evaluate(int t) const
{
return this->left->evaluate(t) <= this->right->evaluate(t);
return left->evaluate(t) <= right->evaluate(t);
};

protected:
Expand All @@ -301,7 +308,7 @@ namespace bb

int evaluate(int t) const
{
return this->left->evaluate(t) >= this->right->evaluate(t);
return left->evaluate(t) >= right->evaluate(t);
};

protected:
Expand All @@ -318,7 +325,7 @@ namespace bb

int evaluate(int t) const
{
return this->left->evaluate(t) == this->right->evaluate(t);
return left->evaluate(t) == right->evaluate(t);
};

protected:
Expand All @@ -335,7 +342,7 @@ namespace bb

int evaluate(int t) const
{
return this->left->evaluate(t) != this->right->evaluate(t);
return left->evaluate(t) != right->evaluate(t);
};

protected:
Expand Down

0 comments on commit fca5654

Please sign in to comment.