tech-kern archive

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

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



One last comment on this:

Other than this header, the only other place in our source tree where
either us2bintime() or ms2bintime() is referenced is in

	./tests/usr.bin/xlint/lint1/d_c99_compound_literal_comma.c

This file is not ever compiled, but simply contains sample code for
testing lint!

So, unless there are any objections, I will change both sys/time.h and
the lint test within the next 24 hours.



On Thu, 5 Jan 2017, Paul Goyette wrote:

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 |
+------------------+--------------------------+------------------------+


+------------------+--------------------------+------------------------+
| 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