Permalink
Browse files

freemheg: Catch divide by zero

Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
Signed-off-by: Stuart Morgan <smorgan@mythtv.org>
  • Loading branch information...
1 parent 2ffbeb8 commit 0a864fdeeff080cda227f9d489f38cd9429765d0 Lawrence Rust committed with stuartm Jul 18, 2011
Showing with 5 additions and 2 deletions.
  1. +5 −2 mythtv/libs/libmythfreemheg/Variables.h
@@ -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 -

0 comments on commit 0a864fd

Please sign in to comment.