Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 27 Feb 2015 10:12:08 -0500
From:      Benjamin Kaduk <bjkfbsd@gmail.com>
To:        Bruce Evans <brde@optusnet.com.au>
Cc:        "svn-src-head@freebsd.org" <svn-src-head@freebsd.org>, "svn-src-all@freebsd.org" <svn-src-all@freebsd.org>, "src-committers@freebsd.org" <src-committers@freebsd.org>, Warner Losh <imp@freebsd.org>, Andrew Turner <andrew@fubar.geek.nz>
Subject:   Re: svn commit: r279349 - head/sys/kern
Message-ID:  <CAJ5_RoCj_D06WK%2BUVrLXNouu252X-6oaaj68RJoQhDzx_wJyAA@mail.gmail.com>
In-Reply-To: <20150227202646.I2088@besplex.bde.org>
References:  <201502270256.t1R2uxnv085328@svn.freebsd.org> <20150227082257.3fb1081c@bender.Home> <20150227202646.I2088@besplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Feb 27, 2015 at 4:56 AM, Bruce Evans <brde@optusnet.com.au> wrote:

> On Fri, 27 Feb 2015, Andrew Turner wrote:
>
>  On Fri, 27 Feb 2015 02:56:59 +0000 (UTC)
>> Warner Losh <imp@FreeBSD.org> wrote:
>> ...
>>
>>>
>>> Didn't we recently have issues with signed integer overflow being
>> undefined? Even though we worked around it with a compiler flag it
>> would be better to not rely on undefined behaviour in the first place.
>>
>
> The undefined behaviour is missing in old rand() in libc.  That uses
> unsigned long internally to avoid the undefined behaviour and to not
> depend on ints being 32 bits, but returns only 15 bits so that the
> value can be represented as a (nonnegative) 16-bit int.  Normally,
> LCGs have a large multiplier that puts most randomness in the top
> bits so lower bits should be discarded.  This one does the opposite.
>


As of r278229, the kernel is compiled with -fwrapv, so signed integer
overflow in the FreeBSD kernel is defined behavior.  n1256.pdf's 3.4.1
example notes that right-shift of signed integer is implementation-defined,
yes.

-Ben



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJ5_RoCj_D06WK%2BUVrLXNouu252X-6oaaj68RJoQhDzx_wJyAA>