From: Peter Stamfest Date: Thu, 6 Mar 2014 07:26:06 +0000 (+0100) Subject: Fix nasty off-by-one error, causing incorrect CDP calculations when adding X-Git-Tag: v1.5.0-rc1~129^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f3c88c641d5e6a120f52fe1e53bc70dc9a042665;p=thirdparty%2Frrdtool-1.x.git Fix nasty off-by-one error, causing incorrect CDP calculations when adding new RRAs --- diff --git a/src/rrd_modify.c b/src/rrd_modify.c index f7a6beac..b1447bba 100644 --- a/src/rrd_modify.c +++ b/src/rrd_modify.c @@ -1039,7 +1039,9 @@ static void prepare_CDPs(const rrd_t *in, rrd_t *out, } } } - +#ifdef MODIFY_DEBUG + fprintf(stderr, "chosen candidate index=%d row_cnt=%ld\n", chosen_candidate->rra_index, chosen_candidate->rra->row_cnt); +#endif int start_cdp_index_out = out->stat_head->ds_cnt * curr_rra; for (int i = 0 ; i < (int) out->stat_head->ds_cnt ; i++) { @@ -1132,7 +1134,7 @@ static void prepare_CDPs(const rrd_t *in, rrd_t *out, ccdp->scratch[CDP_primary_val].u_val; } else { int pre_start = start_row - 1; - if (pre_start == 0) pre_start = chosen_candidate->rra->row_cnt; + if (pre_start < 0) pre_start = chosen_candidate->rra->row_cnt - 1; cdp_prep->scratch[CDP_secondary_val].u_val = chosen_candidate->values[ds_cnt * pre_start + mapped_i]; diff --git a/tests/modify5 b/tests/modify5 index b1342936..bbf00dca 100755 --- a/tests/modify5 +++ b/tests/modify5 @@ -29,7 +29,7 @@ report create 1 $RRDTOOL dump ${BASE}a2.rrd | $DIFF ${BASE}a2-create.dump - report create 2 -for U in 1300003010:200 1300003070:102 1300003130:777 1300003190:645 1300003250:122 1300003310:981 1300003323:223 1300003381:721 +for U in 1300003010:200 1300003070:102 1300003130:777 1300003190:645 1300003250:122 1300003310:981 1300003323:223 1300003381:721 1300003445:821 1300003500:221 1300003562:231 1300003637:542 1300003699:734 1300003769:9231 1300003823:17 do echo ---------------------iterate-------------------------- # update both - both contain same data