svn commit: r279349 - head/sys/kern

Benjamin Kaduk bjkfbsd at gmail.com
Fri Feb 27 15:12:11 UTC 2015


On Fri, Feb 27, 2015 at 4:56 AM, Bruce Evans <brde at 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 at 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


More information about the svn-src-head mailing list