From da91503d8e6d00e76d52b96ab99bf1600fc93c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B6r=C3=B6k=20Edvin?= Date: Fri, 14 May 2010 10:35:16 +0300 Subject: [PATCH] Properly round ilog/iexp/... --- libclamav/bytecode_api.c | 12 ++++++------ libclamav/bytecode_api.h | 2 +- libclamav/bytecode_api_decl.c | 2 +- libclamav/bytecode_api_impl.h | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libclamav/bytecode_api.c b/libclamav/bytecode_api.c index e26748adb..e348278b9 100644 --- a/libclamav/bytecode_api.c +++ b/libclamav/bytecode_api.c @@ -939,23 +939,23 @@ int32_t cli_bcapi_ilog2(struct cli_bc_ctx *ctx, uint32_t a, uint32_t b) return 0x7fffffff; /* log(a/b) is -32..32, so 2^26*32=2^31 covers the entire range of int32 */ f = (1<<26)*log((double)a / b) / log(2); - return (int32_t)f; + return (int32_t)round(f); } int32_t cli_bcapi_ipow(struct cli_bc_ctx *ctx, int32_t a, int32_t b, int32_t c) { if (!a && b < 0) return 0x7fffffff; - return (int32_t)c*pow(a,b); + return (int32_t)round(c*pow(a,b)); } -int32_t cli_bcapi_iexp(struct cli_bc_ctx *ctx, int32_t a, int32_t b, int32_t c) +uint32_t cli_bcapi_iexp(struct cli_bc_ctx *ctx, int32_t a, int32_t b, int32_t c) { double f; if (!b) return 0x7fffffff; f= c*exp((double)a/b); - return (int32_t)f; + return (uint32_t)round(f); } int32_t cli_bcapi_isin(struct cli_bc_ctx *ctx, int32_t a, int32_t b, int32_t c) @@ -964,7 +964,7 @@ int32_t cli_bcapi_isin(struct cli_bc_ctx *ctx, int32_t a, int32_t b, int32_t c) if (!b) return 0x7fffffff; f = c*sin((double)a/b); - return (int32_t)f; + return (int32_t)round(f); } int32_t cli_bcapi_icos(struct cli_bc_ctx *ctx, int32_t a, int32_t b, int32_t c) @@ -973,7 +973,7 @@ int32_t cli_bcapi_icos(struct cli_bc_ctx *ctx, int32_t a, int32_t b, int32_t c) if (!b) return 0x7fffffff; f = c*cos((double)a/b); - return (int32_t)f; + return (int32_t)round(f); } int32_t cli_bcapi_memstr(struct cli_bc_ctx *ctx, const uint8_t* h, int32_t hs, diff --git a/libclamav/bytecode_api.h b/libclamav/bytecode_api.h index c0d247620..d4a6c31bb 100644 --- a/libclamav/bytecode_api.h +++ b/libclamav/bytecode_api.h @@ -446,7 +446,7 @@ int32_t ipow(int32_t a, int32_t b, int32_t c); * @param c integer * @return c*exp(a/b) */ -int32_t iexp(int32_t a, int32_t b, int32_t c); +uint32_t iexp(int32_t a, int32_t b, int32_t c); /** * Returns c*sin(a/b). diff --git a/libclamav/bytecode_api_decl.c b/libclamav/bytecode_api_decl.c index d568dc328..68fe24aec 100644 --- a/libclamav/bytecode_api_decl.c +++ b/libclamav/bytecode_api_decl.c @@ -80,7 +80,7 @@ int32_t cli_bcapi_jsnorm_process(struct cli_bc_ctx *ctx , int32_t); int32_t cli_bcapi_jsnorm_done(struct cli_bc_ctx *ctx , int32_t); int32_t cli_bcapi_ilog2(struct cli_bc_ctx *ctx , uint32_t, uint32_t); int32_t cli_bcapi_ipow(struct cli_bc_ctx *ctx , int32_t, int32_t, int32_t); -int32_t cli_bcapi_iexp(struct cli_bc_ctx *ctx , int32_t, int32_t, int32_t); +uint32_t cli_bcapi_iexp(struct cli_bc_ctx *ctx , int32_t, int32_t, int32_t); int32_t cli_bcapi_isin(struct cli_bc_ctx *ctx , int32_t, int32_t, int32_t); int32_t cli_bcapi_icos(struct cli_bc_ctx *ctx , int32_t, int32_t, int32_t); int32_t cli_bcapi_memstr(struct cli_bc_ctx *ctx , const uint8_t*, int32_t, const uint8_t*, int32_t); diff --git a/libclamav/bytecode_api_impl.h b/libclamav/bytecode_api_impl.h index 7c4d6ddf4..dd852c744 100644 --- a/libclamav/bytecode_api_impl.h +++ b/libclamav/bytecode_api_impl.h @@ -77,7 +77,7 @@ int32_t cli_bcapi_jsnorm_process(struct cli_bc_ctx *ctx , int32_t); int32_t cli_bcapi_jsnorm_done(struct cli_bc_ctx *ctx , int32_t); int32_t cli_bcapi_ilog2(struct cli_bc_ctx *ctx , uint32_t, uint32_t); int32_t cli_bcapi_ipow(struct cli_bc_ctx *ctx , int32_t, int32_t, int32_t); -int32_t cli_bcapi_iexp(struct cli_bc_ctx *ctx , int32_t, int32_t, int32_t); +uint32_t cli_bcapi_iexp(struct cli_bc_ctx *ctx , int32_t, int32_t, int32_t); int32_t cli_bcapi_isin(struct cli_bc_ctx *ctx , int32_t, int32_t, int32_t); int32_t cli_bcapi_icos(struct cli_bc_ctx *ctx , int32_t, int32_t, int32_t); int32_t cli_bcapi_memstr(struct cli_bc_ctx *ctx , const uint8_t*, int32_t, const uint8_t*, int32_t);