Opened 3 years ago

Closed 3 years ago

#22259 closed defect (duplicate)

Stop ignoring hours when using months for bandwidth accounting

Reported by: teor Owned by:
Priority: Medium Milestone: Tor: 0.3.1.x-final
Component: Core Tor/Tor Version:
Severity: Normal Keywords:
Cc: Actual Points:
Parent ID: Points: 0.5
Reviewer: Sponsor:


The current monthly accounting code ignores hours when checking the monthly accounting start date/time.

The fix is:

-        (tm.tm_mday < cfg_start_day && before)) {
+        (tm.tm_mday == cfg_start_day && before)) {

For bonus points, write a unit test that catches the error.

The original bug report was:

I could note just one warning out of all of them, which indicates an error. Let's consider the following code fragment:

static time_t
edge_of_accounting_period_containing(time_t now, int get_end)
  case UNIT_MONTH: {
    if (tm.tm_mday < cfg_start_day ||
        (tm.tm_mday < cfg_start_day && before)) {

PVS-Studio warning: V686 A pattern was detected: (tm.tm_mday < cfg_start_day) || ((tm.tm_mday < cfg_start_day) && ...). The expression is excessive or contains a logical error. hibernate.c 333

The check can be simplified to:

if (tm.tm_mday < cfg_start_day) {

Perhaps, there is a typo or a logical error in this condition.

Reported by Andrey Karpov

Child Tickets

Change History (1)

comment:1 Changed 3 years ago by teor

Resolution: duplicate
Status: newclosed

This is a duplicate of #22245.

Note: See TracTickets for help on using tickets.