On Sun, Feb 27, 2011 at 11:12:03PM +1100, Bruce Evans wrote: > On Sun, 27 Feb 2011, Bruce Cran wrote: > > >On Thu, 2011-02-24 at 10:36 +1100, Bruce Evans wrote: > >> > >>I would cast operand(s) in the expression as necessary to prevent overflow > >>of subexpressions. vm_pindex_t would work, but I prefer to use a type > >>related to the subexpressions. Not sure what that is. Maybe just > >>uintmax_t for safety (even that is not safe if the subexpressions have > >>large values). So: > >> > >> (uintmax_t)swap_bcount * SWAP_META_PAGES * n / mumble. > > > >Following Alan's suggestion, I've attached an updated patch which uses a > >cast to u_long and returns long. > > I thought he only meant to return long. The units being returned are > PAGE_SIZE smaller than the units in the expression. But I don't know > exacty how large swp_bcount can be. If everything fits in a single > object, then vm_size_t = u_int on 32-bit machines is enough.
I think that return type should be left as vm_offset_t. The calculation basically returns some quantity of type vm_offset_t, divided by PAGE_SIZE. This validates the new return type. The calculation could use vm_offset_t, or uintmax_t cast, probably vm_offset_t is preferred for the same reason.
pgpu5aew5KUQ3.pgp
Description: PGP signature