From 9585b38e77fc981fd5ad6ebc3ed91a18c6a2e748 Mon Sep 17 00:00:00 2001
From: Lawrence Rust <lvr@softsystem.co.uk>
Date: Mon, 18 Jul 2011 20:28:30 +0200
Subject: [PATCH 4/9] freemheg: Catch divide by zero
Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
---
mythtv/libs/libmythfreemheg/Variables.h | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/mythtv/libs/libmythfreemheg/Variables.h b/mythtv/libs/libmythfreemheg/Variables.h
index 544a913..2363b06 100644
a
|
b
|
class MHDivide: public MHIntegerAction { |
205 | 205 | public: |
206 | 206 | MHDivide(): MHIntegerAction(":Divide") {} |
207 | 207 | protected: |
208 | | virtual int DoOp(int arg1, int arg2) { return arg1/arg2; } // What about divide by zero? |
| 208 | virtual int DoOp(int arg1, int arg2) { |
| 209 | if (arg2 == 0) throw "Divide by 0"; |
| 210 | return arg1/arg2; |
| 211 | } |
209 | 212 | }; |
210 | 213 | |
211 | 214 | class MHModulo: public MHIntegerAction { |
212 | 215 | public: |
213 | 216 | MHModulo(): MHIntegerAction(":Modulo") {} |
214 | 217 | protected: |
215 | | virtual int DoOp(int arg1, int arg2) { return arg1%arg2; } // What about divide by zero? |
| 218 | virtual int DoOp(int arg1, int arg2) { return arg2 ? arg1%arg2 : 0; } |
216 | 219 | }; |
217 | 220 | |
218 | 221 | // Append - |