From patchwork Mon Feb 9 23:28:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Vesely X-Patchwork-Id: 5803861 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C4020BF440 for ; Mon, 9 Feb 2015 23:28:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0B5A42011B for ; Mon, 9 Feb 2015 23:28:25 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 3BFEE20115 for ; Mon, 9 Feb 2015 23:28:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 924D76E5E3; Mon, 9 Feb 2015 15:28:22 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qc0-f176.google.com (mail-qc0-f176.google.com [209.85.216.176]) by gabe.freedesktop.org (Postfix) with ESMTP id 700486E5E3 for ; Mon, 9 Feb 2015 15:28:21 -0800 (PST) Received: by mail-qc0-f176.google.com with SMTP id c9so25865769qcz.7 for ; Mon, 09 Feb 2015 15:28:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=f8XDGcRNeOCpRl6syUkTfLmBLNiwqz1L8ygswgQMgI4=; b=N4AMl5QS+ailOTRIxSWx8bDNkW8LFoKE0ttRQGFDQ0ejyaTPUwKwUMTldseyR15FZM Bd1gUh8rRREalrtyIbqyWMw4RWeb8b1tLFowaSw8xAH1/KqO/cKzLa0QLGgcSNyKuCLN tv6tWfTBmWH+HoBov25zaW/4Y5nZyrXmHDjwjVpq8XKU3620HtobEL2TvfEx82IrZbDO Offn2aMUCgQ5GjNvCCHYSrtv1QZH2ruJ9bB1lpZnzlKebGIUNB7D9DPZNbnP1Pedi9w9 0sb/6ySCMfZjowt21MUJs6cwz7wylIyvZ0P80XnTu2RNXXE2oZILv4EHBEnRtzYGubGK qtlg== X-Gm-Message-State: ALoCoQlUfuRxnRmS91HFWUtkP4IfLlQmRWTCg7Nt/jzSTH+YJ8UZC4YxsLsRqKpKLjelpXXEhoih X-Received: by 10.224.171.67 with SMTP id g3mr39695310qaz.17.1423524500991; Mon, 09 Feb 2015 15:28:20 -0800 (PST) Received: from adriatix.rutgers.edu ([198.151.130.142]) by mx.google.com with ESMTPSA id a66sm1674187qge.4.2015.02.09.15.28.20 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Feb 2015 15:28:20 -0800 (PST) From: Jan Vesely To: dri-devel@lists.freedesktop.org, Ian Romanick Subject: [libdrm][PATCH v2 1/2] random: Use unsigned long for seed Date: Mon, 9 Feb 2015 18:28:19 -0500 Message-Id: <1423524499-311-1-git-send-email-jan.vesely@rutgers.edu> X-Mailer: git-send-email 2.1.0 In-Reply-To: <54D93E99.4010107@freedesktop.org> References: <54D93E99.4010107@freedesktop.org> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP v2: Remove unrelated change in main() This is more consistent with the rest, and avoids potential undefined behavior (signed overflow) ind drmRandom() Signed-off-by: Jan Vesely Reviewed-by: Ian Romanick --- xf86drmRandom.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/xf86drmRandom.c b/xf86drmRandom.c index ecab9e2..94922ad 100644 --- a/xf86drmRandom.c +++ b/xf86drmRandom.c @@ -98,7 +98,7 @@ typedef struct RandomState { unsigned long q; /* m div a */ unsigned long r; /* m mod a */ unsigned long check; - long seed; + unsigned long seed; } RandomState; #if RANDOM_MAIN @@ -147,13 +147,13 @@ int drmRandomDestroy(void *state) unsigned long drmRandom(void *state) { RandomState *s = (RandomState *)state; - long hi; - long lo; + unsigned long hi; + unsigned long lo; hi = s->seed / s->q; lo = s->seed % s->q; s->seed = s->a * lo - s->r * hi; - if (s->seed <= 0) s->seed += s->m; + if ((s->a * lo) <= (s->r * hi)) s->seed += s->m; return s->seed; } @@ -166,7 +166,7 @@ double drmRandomDouble(void *state) } #if RANDOM_MAIN -static void check_period(long seed) +static void check_period(unsigned long seed) { unsigned long count = 0; unsigned long initial; @@ -178,7 +178,7 @@ static void check_period(long seed) while (initial != drmRandom(state)) { if (!++count) break; } - printf("With seed of %10ld, period = %10lu (0x%08lx)\n", + printf("With seed of %10lu, period = %10lu (0x%08lx)\n", seed, count, count); drmRandomDestroy(state); }