summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Vorontsov <avorontsov@ru.mvista.com>2009-12-04 07:37:56 +0300
committerMark Wielaard <mjw@redhat.com>2009-12-09 23:42:56 +0100
commit268c22b1917243cf1c02f8e1ca39ee83c7297ccc (patch)
tree705671279a8d3fd5dac12c4bc29899e79183ad85
parent965b658f73ff2a6d11198edc1b84a06a900c1fd7 (diff)
downloadsystemtap-steved-268c22b1917243cf1c02f8e1ca39ee83c7297ccc.tar.gz
systemtap-steved-268c22b1917243cf1c02f8e1ca39ee83c7297ccc.tar.xz
systemtap-steved-268c22b1917243cf1c02f8e1ca39ee83c7297ccc.zip
Fix regression in statistic operations
In commit 98c783852039061db8c1611742660aaded0eab77 ("Use proper types for do_div") I imprudently changed some variables to an unsigned type while in some places the code actually relies on a sign. So, let's be a bit smarter now and use temporary variables. Reported-by: Wenji Huang <wenji.huang@oracle.com> Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
-rw-r--r--runtime/stat-common.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/runtime/stat-common.c b/runtime/stat-common.c
index f9703049..fabe8404 100644
--- a/runtime/stat-common.c
+++ b/runtime/stat-common.c
@@ -34,9 +34,10 @@ static int _stp_stat_calc_buckets(int stop, int start, int interval)
return buckets;
}
-static int needed_space(uint64_t v)
+static int needed_space(int64_t v)
{
int space = 0;
+ uint64_t tmp;
if (v == 0)
return 1;
@@ -45,9 +46,10 @@ static int needed_space(uint64_t v)
space++;
v = -v;
}
- while (v) {
+ tmp = v;
+ while (tmp) {
/* v /= 10; */
- do_div (v, 10);
+ do_div(tmp, 10);
space++;
}
return space;
@@ -134,7 +136,8 @@ static void _stp_stat_print_histogram_buf(char *buf, size_t size, Hist st, stat
{
int scale, i, j, val_space, cnt_space;
int low_bucket = -1, high_bucket = 0, over = 0, under = 0;
- uint64_t val, v, valmax = 0;
+ int64_t val, valmax = 0;
+ uint64_t v;
int eliding = 0;
char *cur_buf = buf, *fake = buf;
char **bufptr = (buf == NULL ? &fake : &cur_buf);
@@ -282,7 +285,7 @@ static void _stp_stat_print_histogram(Hist st, stat *sd)
_stp_print_flush();
}
-static void __stp_stat_add (Hist st, stat *sd, uint64_t val)
+static void __stp_stat_add(Hist st, stat *sd, int64_t val)
{
int n;
if (sd->count == 0) {
@@ -310,7 +313,10 @@ static void __stp_stat_add (Hist st, stat *sd, uint64_t val)
if (val < 0)
val = 0;
else {
- do_div (val, st->interval);
+ uint64_t tmp = val;
+
+ do_div(tmp, st->interval);
+ val = tmp;
val++;
}