[PATCH] fadvise(2) system call

Jilles Tjoelker jilles at stack.nl
Wed Nov 2 18:11:42 UTC 2011


On Mon, Oct 31, 2011 at 10:24:07AM -0400, John Baldwin wrote:
> > The comparisons

> > +		    (fa->fa_start != 0 && fa->fa_start == end + 1) ||
> > +		    (uap->offset != 0 && fa->fa_end + 1 == uap->offset))) {

> > should instead be something like

> > +		    (end != OFF_MAX && fa->fa_start == end + 1) ||
> > +		    (fa->fa_end != OFF_MAX && fa->fa_end + 1 == uap->offset))) {

> > to avoid integer overflow.

> Hmm, but the expressions will still work in that case, yes?  I already
> check for uap->offset and uap->len being negative earlier (so fa_start
> and fa_end are always positive), and off_t is signed, so if end is
> OFF_MAX, then end + 1 will certainly not == fa_start?

Signed integer overflow is undefined behaviour; therefore, if you write
end + 1 without checking that end != OFF_MAX, the compiler may assume
that end != OFF_MAX. Whether the compiler will take advantage of this in
ways that cause breakage is another question. For example, if there were
a subsequent check for end != OFF_MAX, the compiler would be allowed to
remove that check. I think it is best not to risk it.

-- 
Jilles Tjoelker


More information about the freebsd-arch mailing list