Date: Tue, 17 Jun 2003 01:59:34 +0100 From: Ian Dowse <iedowse@maths.tcd.ie> To: Bruce Evans <bde@zeta.org.au> Cc: freebsd-arch@FreeBSD.org Subject: Re: Message buffer and printf reentrancy patch Message-ID: <200306170159.aa26127@salmon.maths.tcd.ie> In-Reply-To: Your message of "Mon, 16 Jun 2003 21:13:13 %2B1000." <20030616205631.F28116@gamplex.bde.org>
next in thread | previous in thread | raw e-mail | index | archive | help
In message <20030616205631.F28116@gamplex.bde.org>, Bruce Evans writes:
>On Mon, 16 Jun 2003, Don Lewis wrote:
>> It looks like MSGBUF_SEQNORM() could avoid the conditional code and any
>> questions about signed remainders if it was defined like this:
>>
>> #define MSGBUF_SEQNORM(mbp, seq) (((seq) + (mbp)->msg_seqmod) % \
>> (mbp)->msg_seqmod)
>>
>> as long as msg_seqmod < INT_MAX/2. MSGBUF_SEQNORM() could be simplified
>> further if msg_seqmod was added by the caller (such as MSGBUF_SEQSUB())
>> if the argument could be negative.
>
>Yes. The negative numbers of interest seem to be limited to at most
>differences of sequence numbers (or maybe differeces of indexes, which
>are smaller), so they are larger than -msg_seqmod. MSGBUF_SEQSUB()
>shouldn't add the bias, however, since it is used in contexts where
>we really want to see the negative values.
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.:
#define MSGBUF_SEQNORM(mbp, seq) ((int)((u_int)((seq) + \
(mbp)->msg_seqmod) % (mbp)->msg_seqmod))
This should do the right thing for the expected ranges, but also
ensures that the macro itself can never return an out-of-range
sequence number, whatever the input value.
Ian
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200306170159.aa26127>
