From d41d43a23c18e593aa7a981da52d4ef4db13039e Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 21 Sep 2005 12:04:05 +0000 Subject: [PATCH] *** empty log message *** --- ase/lsp/error.c | 5 +++-- ase/lsp/lsp.h | 5 +++-- ase/lsp/prim_math.c | 20 +++++++++++++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/ase/lsp/error.c b/ase/lsp/error.c index c0bb411a..791d55e6 100644 --- a/ase/lsp/error.c +++ b/ase/lsp/error.c @@ -1,5 +1,5 @@ /* - * $Id: error.c,v 1.1 2005-09-19 12:04:00 bacon Exp $ + * $Id: error.c,v 1.2 2005-09-21 12:04:05 bacon Exp $ */ #include @@ -26,7 +26,8 @@ static const xp_char_t* __errstr[] = XP_TEXT("bad symbol"), XP_TEXT("undefined symbol"), XP_TEXT("empty body"), - XP_TEXT("bad value") + XP_TEXT("bad value"), + XP_TEXT("divide by zero") }; int xp_lsp_error (xp_lsp_t* lsp, xp_char_t* buf, xp_size_t size) diff --git a/ase/lsp/lsp.h b/ase/lsp/lsp.h index 3d21d792..04a029e7 100644 --- a/ase/lsp/lsp.h +++ b/ase/lsp/lsp.h @@ -1,5 +1,5 @@ /* - * $Id: lsp.h,v 1.16 2005-09-20 14:38:39 bacon Exp $ + * $Id: lsp.h,v 1.17 2005-09-21 12:04:05 bacon Exp $ */ #ifndef _XP_LSP_LSP_H_ @@ -39,7 +39,8 @@ enum XP_LSP_ERR_BAD_SYMBOL, XP_LSP_ERR_UNDEF_SYMBOL, XP_LSP_ERR_EMPTY_BODY, - XP_LSP_ERR_BAD_VALUE + XP_LSP_ERR_BAD_VALUE, + XP_LSP_ERR_DIVIDE_BY_ZERO }; /* diff --git a/ase/lsp/prim_math.c b/ase/lsp/prim_math.c index f9733ae6..fe4232be 100644 --- a/ase/lsp/prim_math.c +++ b/ase/lsp/prim_math.c @@ -1,5 +1,5 @@ /* - * $Id: prim_math.c,v 1.4 2005-09-20 12:06:51 bacon Exp $ + * $Id: prim_math.c,v 1.5 2005-09-21 12:04:05 bacon Exp $ */ #include @@ -225,8 +225,13 @@ xp_lsp_obj_t* xp_lsp_prim_divide (xp_lsp_t* lsp, xp_lsp_obj_t* args) ivalue = XP_LSP_IVALUE(tmp); } else { - if (!realnum) + if (!realnum) { + if (XP_LSP_IVALUE(tmp) == 0) { + lsp->errnum = XP_LSP_ERR_DIVIDE_BY_ZERO; + return XP_NULL; + } ivalue = ivalue / XP_LSP_IVALUE(tmp); + } else rvalue = rvalue / XP_LSP_IVALUE(tmp); } @@ -286,6 +291,10 @@ xp_lsp_obj_t* xp_lsp_prim_modulus (xp_lsp_t* lsp, xp_lsp_obj_t* args) ivalue = XP_LSP_IVALUE(tmp); } else { + if (XP_LSP_IVALUE(tmp) == 0) { + lsp->errnum = XP_LSP_ERR_DIVIDE_BY_ZERO; + return XP_NULL; + } ivalue = ivalue % XP_LSP_IVALUE(tmp); } } @@ -294,7 +303,12 @@ xp_lsp_obj_t* xp_lsp_prim_modulus (xp_lsp_t* lsp, xp_lsp_obj_t* args) ivalue = (xp_lsp_int_t)XP_LSP_RVALUE(tmp); } else { - ivalue = ivalue % (xp_lsp_int_t)XP_LSP_RVALUE(tmp); + xp_lsp_int_t tmpi = (xp_lsp_int_t)XP_LSP_RVALUE(tmp); + if (tmpi == 0) { + lsp->errnum = XP_LSP_ERR_DIVIDE_BY_ZERO; + return XP_NULL; + } + ivalue = ivalue % tmpi; } } else {