oetiker/rrdtool-1.x — pull request #557 by bragatto (2014-11-18 00:14:41+00:00)
Title: Fixed started and ending times for RRD xport

Hi,

The function rrd_xport_fn() had this piece of code:

*start = im->start - im->start % (*step);
*end = im->end - im->end % (*step) + (*step);

In the case of "start", when the start time is an exact multiple of step, we have: "im->start % (*step) == 0". In this case the variable "start" is left unchanged, however, later on rrd_tool.c, after calling rrd_xport() (which internally calls rrd_xport_fn()), it's assumed that the start time was moved back to the previous step (which would be the case if "im->start % (*step) > 0" in rrd_xport_fn()). Because of wrong the assumption that the start time is always one step back after calling rrd_xport_fn(), the code always use "start + step" as starting point inside rrd_tool.c.

Likewise, the same was happening for the ending time, but in that case the step was incremented by one step unnecessarily when "im->end % (*step) == 0" in the code from rrd_xport_fn() mentioned above.

I have fixed the rrd_xport_fn() to always return the correct start and end times, so there's no need for rrd_tool.c to add a step to start, and the end time will not be incremented one step when it's already a multiple of step anymore.

Let me know if there are any further questions on the modifications I've made. I admit my description of the problem might not be very clear.