Re: Panic after updating

From: Ian Lepore <ian_at_freebsd.org>
Date: Tue, 12 Jan 2021 12:01:18 -0700
On Tue, 2021-01-12 at 19:56 +0100, Hans Petter Selasky wrote:
> On 1/12/21 7:45 PM, Ian Lepore wrote:
> > > > -       for (int i = 0; i <= sc->sc_npins; i++) {
> > > > +       for (int i = 0; i != sc->sc_npins; i++) {
> > > >                  mtx_destroy(&sc->sc_pin_intr[i].mtx);
> > > >                  free(&sc->sc_pin_intr[i].pin, M_GPIOC);
> > > >          }
> > > 
> > > --HPS
> > > 
> > 
> > If that is the problem, I'd rather see it fixed by using the
> > idiomatic
> > i < sc->sc_npins rather than the non-standard != test.  (But I
> > don't
> > feel strongly enough about it to learn how to use git and commit
> > the
> > fix myself.)
> 
> Hi Ian,
> 
> I think it is more serious that the iteration variable is declared 
> inside the for-loop :-)
> 
> At least it is pretty obvious that the array written is one element
> too 
> small. I've always used != instead of <= in for-loops. But if there
> is a 
> certain style in there, I'm good with < too, though I've always seen
> < 
> as an overhead compared to != , because to implement < you need a 
> subtraction, while != is just a comparison ...
> 
> --HPS

I thought we recently changed (or at least discussed changing) style(9)
to allow for that sort of loop-iter-var declaration.

On most of the chips I know assembly language for (mostly risc chips),
there is no difference between a comparison and a subtraction at the
chip-instruction level.  That is, at the chip level, comparision
instructions are typically implemented as a subtraction that sets
condition code bits but doesn't store the result back to a register.

-- Ian
Received on Tue Jan 12 2021 - 18:01:41 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:41:26 UTC