Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86148 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59394 invoked from network); 10 May 2015 10:40:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 May 2015 10:40:43 -0000 Authentication-Results: pb1.pair.com smtp.mail=lauri.kentta@gmail.com; spf=softfail; sender-id=softfail Authentication-Results: pb1.pair.com header.from=lauri.kentta@gmail.com; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain gmail.com does not designate 195.197.172.116 as permitted sender) X-PHP-List-Original-Sender: lauri.kentta@gmail.com X-Host-Fingerprint: 195.197.172.116 gw02.mail.saunalahti.fi Received: from [195.197.172.116] ([195.197.172.116:43105] helo=gw02.mail.saunalahti.fi) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C5/54-19875-AA53F455 for ; Sun, 10 May 2015 06:40:42 -0400 Received: from tuikku (a91-154-97-170.elisa-laajakaista.fi [91.154.97.170]) by gw02.mail.saunalahti.fi (Postfix) with ESMTP id 3E48240004 for ; Sun, 10 May 2015 13:40:38 +0300 (EEST) Received: from a91-154-97-170.elisa-laajakaista.fi ([91.154.97.170] helo=tuikku.localdomain) by tuikku with esmtpsa (TLSv1.2:AES128-SHA256:128) (Exim 4.85) (envelope-from ) id 1YrOf0-0003RF-5R for internals@lists.php.net; Sun, 10 May 2015 13:40:38 +0300 To: internals@lists.php.net Date: Sun, 10 May 2015 13:40:29 +0300 Message-ID: <1431254429-13179-1-git-send-email-lauri.kentta@gmail.com> X-Mailer: git-send-email 2.4.0 Subject: [PATCH] random_int: Fix power of two check. From: lauri.kentta@gmail.com (=?UTF-8?q?Lauri=20Kentt=C3=A4?=) (x & ~x) is always 0. ((x & (~x + 1)) != x) works. ((x & (x - 1)) != 0) works too. --- ext/standard/random.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/standard/random.c b/ext/standard/random.c index 12c2503..4a1adbf 100644 --- a/ext/standard/random.c +++ b/ext/standard/random.c @@ -182,7 +182,7 @@ PHP_FUNCTION(random_int) umax++; /* Powers of two are not biased */ - if ((umax & ~umax) != umax) { + if ((umax & (umax - 1)) != 0) { /* Ceiling under which ZEND_LONG_MAX % max == 0 */ zend_ulong limit = ZEND_ULONG_MAX - (ZEND_ULONG_MAX % umax) - 1; -- 2.4.0