From owner-svn-src-head@freebsd.org Tue Dec 6 19:08:30 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5B738C6A177; Tue, 6 Dec 2016 19:08:30 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2B5781723; Tue, 6 Dec 2016 19:08:30 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uB6J8TwG025862; Tue, 6 Dec 2016 19:08:29 GMT (envelope-from ed@FreeBSD.org) Received: (from ed@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uB6J8TMS025860; Tue, 6 Dec 2016 19:08:29 GMT (envelope-from ed@FreeBSD.org) Message-Id: <201612061908.uB6J8TMS025860@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ed set sender to ed@FreeBSD.org using -f From: Ed Schouten Date: Tue, 6 Dec 2016 19:08:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r309650 - head/lib/libc/gen X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Dec 2016 19:08:30 -0000 Author: ed Date: Tue Dec 6 19:08:29 2016 New Revision: 309650 URL: https://svnweb.freebsd.org/changeset/base/309650 Log: Properly sign extend the result of jrand48() and mrand48(). These functions are supposed to return a value between [_2^31, 2^31). This doesn't seem to work on 64-bit systems, where we return a value between [0, 3^32). Patch up the function to use proper casts to int32_t. While there, fix some other style bugs. MFC after: 2 weeks Modified: head/lib/libc/gen/jrand48.c head/lib/libc/gen/mrand48.c Modified: head/lib/libc/gen/jrand48.c ============================================================================== --- head/lib/libc/gen/jrand48.c Tue Dec 6 18:58:42 2016 (r309649) +++ head/lib/libc/gen/jrand48.c Tue Dec 6 19:08:29 2016 (r309650) @@ -14,11 +14,14 @@ #include __FBSDID("$FreeBSD$"); +#include + #include "rand48.h" long jrand48(unsigned short xseed[3]) { + _dorand48(xseed); - return ((long) xseed[2] << 16) + (long) xseed[1]; + return ((int32_t)(((uint32_t)xseed[2] << 16) | (uint32_t)xseed[1])); } Modified: head/lib/libc/gen/mrand48.c ============================================================================== --- head/lib/libc/gen/mrand48.c Tue Dec 6 18:58:42 2016 (r309649) +++ head/lib/libc/gen/mrand48.c Tue Dec 6 19:08:29 2016 (r309650) @@ -14,6 +14,8 @@ #include __FBSDID("$FreeBSD$"); +#include + #include "rand48.h" extern unsigned short _rand48_seed[3]; @@ -21,6 +23,8 @@ extern unsigned short _rand48_seed[3]; long mrand48(void) { + _dorand48(_rand48_seed); - return ((long) _rand48_seed[2] << 16) + (long) _rand48_seed[1]; + return ((int32_t)(((uint32_t)_rand48_seed[2] << 16) | + (uint32_t)_rand48_seed[1])); }