Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • Trac Trac
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Issues 246
    • Issues 246
    • List
    • Boards
    • Service Desk
    • Milestones
  • Monitor
    • Monitor
    • Metrics
    • Incidents
  • Analytics
    • Analytics
    • Value stream
  • Wiki
    • Wiki
  • Activity
  • Create a new issue
  • Issue Boards
Collapse sidebar
  • Legacy
  • TracTrac
  • Issues
  • #22259

Closed (moved)
(moved)
Open
Created May 15, 2017 by teor@teor

Stop ignoring hours when using months for bandwidth accounting

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)) {
      --tm.tm_mon;
    }
  ....
}

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 https://www.viva64.com/en/b/0507/

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking