diff options
-rw-r--r-- | runtime/ChangeLog | 8 | ||||
-rw-r--r-- | runtime/arith.c | 26 | ||||
-rw-r--r-- | runtime/stat-common.c | 6 |
3 files changed, 22 insertions, 18 deletions
diff --git a/runtime/ChangeLog b/runtime/ChangeLog index bbff766f..b0eebe87 100644 --- a/runtime/ChangeLog +++ b/runtime/ChangeLog @@ -1,3 +1,11 @@ +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. + 2005-09-08 Martin Hunt <hunt@redhat.com> * arith.c (_stp_div64): Check for overflow. (_stp_mod64): Ditto. 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 } diff --git a/runtime/stat-common.c b/runtime/stat-common.c index ff19662b..55f2ad38 100644 --- a/runtime/stat-common.c +++ b/runtime/stat-common.c @@ -173,10 +173,8 @@ static void _stp_stat_print_valtype (char *fmt, Stat st, struct stat_data *sd, i case 'A': { int64_t avg = 0; - if (sd->count) { - avg = sd->sum; - do_div (avg, (int)sd->count); /* FIXME: check for overflow */ - } + if (sd->count) + avg = _stp_div64 (NULL, sd->sum, sd->count); _stp_printf("%lld", avg); break; } |