summaryrefslogtreecommitdiffstats
path: root/runtime/arith.c
diff options
context:
space:
mode:
authorhunt <hunt>2005-09-09 09:12:37 +0000
committerhunt <hunt>2005-09-09 09:12:37 +0000
commit1431278aba3347fdb55ec461008a07d9010aea7a (patch)
treeb11b30f9c1d46ae1f2ab75a4bd529463f71be79f /runtime/arith.c
parent60a1b0ceedecf422af6b043186092986685efb59 (diff)
downloadsystemtap-steved-1431278aba3347fdb55ec461008a07d9010aea7a.tar.gz
systemtap-steved-1431278aba3347fdb55ec461008a07d9010aea7a.tar.xz
systemtap-steved-1431278aba3347fdb55ec461008a07d9010aea7a.zip
2005-09-09 Martin Hunt <hunt@redhat.com>
* stat-common.c (_stp_stat_print_valtype): Use _stp_div64(). * arith.c (_stp_div64): Check error before writing to it. Remove check against 32-bit LONG_MIN and -1. That only applies to 64-bit. (_stp_mod64): Ditto.
Diffstat (limited to 'runtime/arith.c')
-rw-r--r--runtime/arith.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/runtime/arith.c b/runtime/arith.c
index ee75e4f8..abbac66c 100644
--- a/runtime/arith.c
+++ b/runtime/arith.c
@@ -32,24 +32,23 @@ int64_t _stp_div64 (const char **error, int64_t x, int64_t y)
{
#ifdef __LP64__
if (unlikely (y == 0 || (x == LONG_MIN && y == -1))) {
- *error = "divisor out of range";
+ if (error) *error = "divisor out of range";
return 0;
}
return x/y;
#else
- if (likely ((x >= LONG_MIN && x <= LONG_MAX) && (y >= LONG_MIN && y <= LONG_MAX))) {
+ if (likely ((x > LONG_MIN && x < LONG_MAX) && (y > LONG_MIN && y < LONG_MAX))) {
long xx = (long) x;
long yy = (long) y;
- // check for division-by-zero and overflow
- if (unlikely (yy == 0 || (xx == LONG_MIN && yy == -1))) {
- *error = "divisor out of range";
+ // check for division-by-zero
+ if (unlikely (yy == 0 )) {
+ if (error) *error = "division by 0";
return 0;
}
return xx / yy;
- } else {
+ } else
return _div64 (x, y);
- }
#endif
}
@@ -61,26 +60,25 @@ int64_t _stp_mod64 (const char **error, int64_t x, int64_t y)
{
#ifdef __LP64__
if (unlikely (y == 0 || (x == LONG_MIN && y == -1))) {
- *error = "divisor out of range";
+ if (error) *error = "divisor out of range";
return 0;
}
return x%y;
#else
- if (likely ((x >= LONG_MIN && x <= LONG_MAX) && (y >= LONG_MIN && y <= LONG_MAX))) {
+ if (likely ((x > LONG_MIN && x < LONG_MAX) && (y > LONG_MIN && y < LONG_MAX))) {
long xx = (long) x;
long yy = (long) y;
- // check for division-by-zero and overflow
- if (unlikely (yy == 0 || (xx == LONG_MIN && yy == -1))) {
- *error = "divisor out of range";
+ // check for division-by-zero
+ if (unlikely (yy == 0)) {
+ if (error) *error = "division by 0";
return 0;
}
return xx % yy;
- } else {
+ } else
return _mod64 (x,y);
- }
#endif
}