* patrick keshishian <sids...@boxsoft.com> [2012-04-11 14:55]:
> On Wed, Apr 11, 2012 at 12:20:30PM +0200, Henning Brauer wrote:
> don't you need two different index vars for this next
> section?

no, why?

> > +   for (i = 0; i < n; i++)
> > +           if (i < npflogifs)
> > +                   p[i] = pflogifs[i];
> > +           else
> > +                   p[i] = NULL;

i think that is pretty clear: each slot in the newly allocated p gets
the same value as it had in the old pflogifs, once we're at the end of
pflogifs we set the remaining slots to NULL. unused slots were NULL
before so just inheriting the NULL is safe.

> something like the following with caveats that a) it is
> 5am-ish for me and b) i did not try compiling it:
> 
>       for (i = 0, j = 0; i < n; i++, j++) {
>               for (; j < npflogifs && NULL == pflogifs[j]; j++)
>                       ;
>               if (j == npflogifs)
>                       break;
>               p[i] = pflogifs[j];
>       }
>       for (; i < n; i++)
>               p[i] = NULL;

i gave up following this after a bit.

> > +
> > +   if(pflogifs)
>          ^^ nit

fixed

> >     s = splnet();
> >     pflogifs[pflogif->sc_unit] = NULL;
> >     LIST_REMOVE(pflogif, sc_list);
> > +
> > +   for (i = npflogifs; i > 0 && pflogifs[i - 1] != NULL; i--)
> > +           ; /* nothing */
> > +   if (i < npflogifs)
> > +           pflogifs_resize(i);     /* error harmless here */
> 
> So, if the last pflogifs entry is NULL don't resize
> down? Not really questioning the logic, but want to
> make sure I understand that's what is meant, cause
> there is an easier check for that than the for()-loop.
> Caveats: a) 5am-ish, b) not familiar with code.

walk the array backwards until we find the first non-empty slot, then
shrink it to that.

-- 
Henning Brauer, h...@bsws.de, henn...@openbsd.org
BS Web Services, http://bsws.de, Full-Service ISP
Secure Hosting, Mail and DNS Services. Dedicated Servers, Root to Fully Managed
Henning Brauer Consulting, http://henningbrauer.com/

Reply via email to