On Fri, Feb 27, 2015 at 4:56 AM, Bruce Evans <b...@optusnet.com.au> wrote:
> On Fri, 27 Feb 2015, Andrew Turner wrote: > > On Fri, 27 Feb 2015 02:56:59 +0000 (UTC) >> Warner Losh <i...@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 _______________________________________________ svn-src-head@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"