Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 18 Jun 2003 01:18:59 +0100
From:      Ian Dowse <iedowse@maths.tcd.ie>
To:        Don Lewis <truckman@FreeBSD.org>
Cc:        freebsd-arch@FreeBSD.org
Subject:   Re: Message buffer and printf reentrancy patch 
Message-ID:  <200306180119.aa03806@salmon.maths.tcd.ie>
In-Reply-To: Your message of "Mon, 16 Jun 2003 21:10:33 PDT." <200306170410.h5H4AXM7050537@gw.catspoiler.org> 

next in thread | previous in thread | raw e-mail | index | archive | help
In message <200306170410.h5H4AXM7050537@gw.catspoiler.org>, Don Lewis writes:
>Since MSGBUF_SEQSUB() calls MSGBUF_SEQNORM() on the difference between
>the sequence numbers, a negative value will never be returned.  If you
>want a signed result, you'll probably want to do something more like:
>	tmp = MSGBUF_SEQNORM(mbp, (seq1) - (seq2) + (mbp)->seqmod);
>	return (tmp < ((mbp)->seqmod / 2)) ? tmp : (tmp - (mbp)->seqmod));
>
>and you'll have to use a slightly different function if you are
>comparing indexes.

Oops, you're quite right - MSGBUF_SEQSUB was intended to return
negative values, but got broken somewhere along the way. This appears
not to affect the code that uses it, so I guess that means that the
sequence numbers might as well be unsigned after all.

>> The only minor problem I see with the above is that it is fragile
>> with respect to arbitrary input sequence numbers, in that it could
>> return a negative value. However, the property of guaranteeing to
>> return a normalised sequence number can be achieved by forcing an
>> unsigned division like in MSGBUF_SEQ_TO_POS, i.e.:
>
>Wouldn't it be better to have assertions to detect obviously bogus
>sequence numbers rather than using them to generate a valid pointer to a
>random location in the message buffer?

It would if the assertion didn't trigger a panic that gets written
to the message buffer via the same macros :-)

Ian




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200306180119.aa03806>