Ticket #10019: 0004-freemheg-Catch-divide-by-zero.patch

File 0004-freemheg-Catch-divide-by-zero.patch, 1.2 KB (added by Lawrence Rust <lvr@…>, 13 years ago)
  • mythtv/libs/libmythfreemheg/Variables.h

    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 { 
    205205  public:
    206206    MHDivide(): MHIntegerAction(":Divide") {}
    207207  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    }
    209212};
    210213
    211214class MHModulo: public MHIntegerAction {
    212215  public:
    213216    MHModulo(): MHIntegerAction(":Modulo") {}
    214217  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; }
    216219};
    217220
    218221// Append -