Skip to content

Commit

Permalink
freemheg: Catch divide by zero
Browse files Browse the repository at this point in the history
Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
Signed-off-by: Stuart Morgan <smorgan@mythtv.org>
  • Loading branch information
Lawrence Rust authored and stuartm committed Jul 6, 2012
1 parent 2ffbeb8 commit 0a864fd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions mythtv/libs/libmythfreemheg/Variables.h
Expand Up @@ -205,14 +205,17 @@ class MHDivide: public MHIntegerAction {
public:
MHDivide(): MHIntegerAction(":Divide") {}
protected:
virtual int DoOp(int arg1, int arg2) { return arg1/arg2; } // What about divide by zero?
virtual int DoOp(int arg1, int arg2) {
if (arg2 == 0) throw "Divide by 0";
return arg1/arg2;
}
};

class MHModulo: public MHIntegerAction {
public:
MHModulo(): MHIntegerAction(":Modulo") {}
protected:
virtual int DoOp(int arg1, int arg2) { return arg1%arg2; } // What about divide by zero?
virtual int DoOp(int arg1, int arg2) { return arg2 ? arg1%arg2 : 0; }
};

// Append -
Expand Down

0 comments on commit 0a864fd

Please sign in to comment.