tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Typo(s) in sys/time.h ?



On Thu, 5 Jan 2017, Paul Goyette wrote:

Currently, we have

static __inline struct bintime
ms2bintime(uint64_t ms)
{
       struct bintime bt;

       bt.sec = (time_t)(ms / 1000U);
       bt.frac = (((ms % 1000U) >> 32)/1000U) >> 32;

       return bt;
}

As far as I can tell, this will result in bt.frac always set to zero,
since the (ms % 1000U) portion is a number less than 1000, and if you
shift a number less than 1000 to the right by 32 bits, you end up with
zero!

I suspect we should have a left shift here, rather than a right shift:

       bt.frac = (((ms % 1000U) << 32)/1000U) >> 32;

---------------------------------^^           ^^
                                                ^^
also here --------------------------------------^^


The same issue exists for us2bintime()



+------------------+--------------------------+------------------------+
| Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:      |
| (Retired)        | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com   |
| Kernel Developer | 0786 F758 55DE 53BA 7731 | pgoyette at netbsd.org |
+------------------+--------------------------+------------------------+


Home | Main Index | Thread Index | Old Index