tech-userlevel archive

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

RE: pdksh



> -----Original Message-----
> From: tech-userlevel-owner%NetBSD.org@localhost [mailto:tech-userlevel-
> owner%NetBSD.org@localhost] On Behalf Of Richard PALO
> Sent: Sunday, May 17, 2015 7:27
> To: tech-userlevel%netbsd.org@localhost
> Subject: pdksh
> 
> > @@ -122,7 +126,7 @@ tenter(tp, n, h)
> >         }
> >
> >         if (tp->nfree <= 0) {   /* too full */
> > -               texpand(tp, 2*tp->size);
> > +               texpand(tp, min(INTMAX_MAX, 2*tp->size));
> >                 goto Search;
> >         }

Given that tp->size is an INT, 2*tp->size will be calculated as an int, not as intmax_t.  So I don't think comparing to INTMAX_MAX does any good.

In any case, comparing after multiplying is usually a bad idea. You need instead something like:

	2 * min(INT_MAX/2, tp->size)

(This assumes that 2 * (INT_MAX/2) will be <= INT_MAX, which is true for 2's complement arithmetic.)

Best regards,
--Terry



Home | Main Index | Thread Index | Old Index