On Thu, Jul 25, 2019 at 09:47:53AM -0500, Scott Cheloha wrote:
> On Thu, Jul 25, 2019 at 08:33:25AM -0600, Todd C. Miller wrote:
> > On Wed, 24 Jul 2019 19:05:16 -0500, Scott Cheloha wrote:
> > 
> > > We can simplify the itimerdecr() code with the sys/time.h macros.
> > > I think this is a lot easier to decipher.
> > >
> > > With the macros we don't need special logic to correctly handle the
> > > reload if the decrement exceeds the time remaining in the itimer.
> > >
> > > With the loop we now correctly handle decrements larger than our
> > > interval.  Maybe someone can make use of that.  Using the loop instead
> > > of just an if-clause doesn't complicate our code so I figure we might
> > > as well do the right thing in that case.
> > 
> > This looks correct and is much shorter.  I do find mixing explicit
> > checks of tv_sec with timerisset a little confusing, but maybe that
> > is just me.
> > 
> > For example, instead of this:
> > 
> >     if (itp->it_value.tv_sec >= 0 && timerisset(&itp->it_value))
> > 
> > I find the following easier to read:
> > 
> >     if (itp->it_value.tv_sec >= 0 && itp->it_value.tv_usec > 0)
> > 
> > (yes, I know the tv_usec could just be != 0).

*ahem*

Woohoo, slow morning, nearly missed that bug.  Your conditional
is incorrect because it rejects timevals of whole seconds, e.g.
tv_sec == 1 and tv_usec == 0.

So I will not be using it.

This actually lends credence to the utility of a "timerisexpired"
macro, if only because people look at conditionals like that and think
they might be equivalent.  Food for thought.

Reply via email to