projects
/
rrdtool.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
prevent potential segfaults on boxes where time_t is not long
[rrdtool.git]
/
src
/
rrd_rpncalc.c
diff --git
a/src/rrd_rpncalc.c
b/src/rrd_rpncalc.c
index
9078b30
..
7953320
100644
(file)
--- a/
src/rrd_rpncalc.c
+++ b/
src/rrd_rpncalc.c
@@
-172,6
+172,7
@@
void rpn_compact2str(
add_op(OP_SORT, SORT)
add_op(OP_REV, REV)
add_op(OP_TREND, TREND)
add_op(OP_SORT, SORT)
add_op(OP_REV, REV)
add_op(OP_TREND, TREND)
+ add_op(OP_TRENDNAN, TRENDNAN)
add_op(OP_RAD2DEG, RAD2DEG)
add_op(OP_DEG2RAD, DEG2RAD)
add_op(OP_AVG, AVG)
add_op(OP_RAD2DEG, RAD2DEG)
add_op(OP_DEG2RAD, DEG2RAD)
add_op(OP_AVG, AVG)
@@
-364,6
+365,7
@@
rpnp_t *rpn_parse(
match_op(OP_SORT, SORT)
match_op(OP_REV, REV)
match_op(OP_TREND, TREND)
match_op(OP_SORT, SORT)
match_op(OP_REV, REV)
match_op(OP_TREND, TREND)
+ match_op(OP_TRENDNAN, TRENDNAN)
match_op(OP_RAD2DEG, RAD2DEG)
match_op(OP_DEG2RAD, DEG2RAD)
match_op(OP_AVG, AVG)
match_op(OP_RAD2DEG, RAD2DEG)
match_op(OP_DEG2RAD, DEG2RAD)
match_op(OP_AVG, AVG)
@@
-757,6
+759,7
@@
short rpn_calc(
}
break;
case OP_TREND:
}
break;
case OP_TREND:
+ case OP_TRENDNAN:
stackunderflow(1);
if ((rpi < 2) || (rpnp[rpi - 2].op != OP_VARIABLE)) {
rrd_set_error("malformed trend arguments");
stackunderflow(1);
if ((rpi < 2) || (rpnp[rpi - 2].op != OP_VARIABLE)) {
rrd_set_error("malformed trend arguments");
@@
-766,16
+769,24
@@
short rpn_calc(
time_t step = (time_t) rpnp[rpi - 2].step;
if (output_idx > (int) ceil((float) dur / (float) step)) {
time_t step = (time_t) rpnp[rpi - 2].step;
if (output_idx > (int) ceil((float) dur / (float) step)) {
+ int ignorenan = (rpnp[rpi].op == OP_TREND);
double accum = 0.0;
int i = 0;
double accum = 0.0;
int i = 0;
+ int count = 0;
do {
do {
-
accum +
=
+
double val
=
rpnp[rpi - 2].data[rpnp[rpi - 2].ds_cnt * i--];
rpnp[rpi - 2].data[rpnp[rpi - 2].ds_cnt * i--];
+ if (ignorenan || !isnan(val)) {
+ accum += val;
+ ++count;
+ }
+
dur -= step;
} while (dur > 0);
dur -= step;
} while (dur > 0);
- rpnstack->s[--stptr] = (accum / -i);
+ rpnstack->s[--stptr] =
+ (count == 0) ? DNAN : (accum / count);
} else
rpnstack->s[--stptr] = DNAN;
}
} else
rpnstack->s[--stptr] = DNAN;
}