]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Accept zero delta in libdbi /derive (#550)
authorTobias Oetiker <tobi@oetiker.ch>
Tue, 26 May 2026 14:46:35 +0000 (16:46 +0200)
committerTobias Oetiker <tobi@oetiker.ch>
Tue, 26 May 2026 14:46:35 +0000 (16:46 +0200)
When a counter is constant between two samples the delta is zero.
The previous guard `d_value > 0` treated that the same as a negative
delta (counter reset) and returned NaN instead of 0.  Changing to
`d_value >= 0` preserves the counter-reset protection while correctly
returning 0.0 for a flat counter.

Reported by @bitionaire, fix by @oetiker.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
CHANGES
src/rrd_fetch_libdbi.c

diff --git a/CHANGES b/CHANGES
index fe64e8880051d0023c4f0f621f7b7a5ef8eeff58..0df8f3f88619d97f70dd6802c390237f621d3771 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -3,6 +3,11 @@ RRDtool - master ...
 ====================
 Bugfixes
 --------
+* libdbi /derive now returns 0 instead of NaN when the underlying
+  counter is constant (zero delta). Previously the strict `d_value > 0`
+  guard skipped zero deltas the same way it skips negative ones (counter
+  resets). Changed to `d_value >= 0`. Issue #550 reported by
+  @bitionaire, fix by @oetiker.
 * Pad the Perl `$RRDs::VERSION` / `$RRDp::VERSION` numeric encoding so
   two-digit minor releases compare monotonically. The numeric version
   now uses three-digit zero-padded minor and patch fields, e.g.
index a3ee01cc3f2c5cfbdb9df3bd985d1809acbb5e82..044442ccf05706f083c26f4d466d8338cdffe924 100644 (file)
@@ -706,8 +706,8 @@ rrd_fetch_fn_libdbi(
       r_value=DNAN;
       /* check for timestamp delta to be within an acceptable range */
       if ((d_timestamp>0)&&(d_timestamp<2*derive)) {
-       /* only handle positive delta - avoid wrap-arounds/counter resets showing up as spikes */
-       if (d_value>0) {
+       /* only handle non-negative delta - avoid wrap-arounds/counter resets showing up as spikes */
+       if (d_value>=0) {
          /* and normalize to per second */
          r_value=d_value/d_timestamp;
        }