From: Dave Jones <davej@redhat.com>
To: Vince Weaver <vincent.weaver@maine.edu>
Cc: trinity@vger.kernel.org
Subject: Re: [patch] fix divide by zero in random/taviso()
Date: Fri, 17 Jan 2014 16:03:56 -0500 [thread overview]
Message-ID: <20140117210356.GA10744@redhat.com> (raw)
In-Reply-To: <alpine.DEB.2.10.1401171541490.6771@vincent-weaver-1.um.maine.edu>
On Fri, Jan 17, 2014 at 03:41:58PM -0500, Vince Weaver wrote:
> I'm not sure if this is the cleanest fix for the issue, but it seems to
> work for me.
Good enough.
> In random.c the taviso() routine uses "rand() % rand()" which
> can cause a floating point exception if rand() returns 0.
> Add some tests to make sure that doesn't happen.
>
> Signed-off-by: Vince Weaver <vincent.weaver@maine.edu>
>
> diff --git a/random.c b/random.c
> index 7def9ff..a71fcea 100644
> --- a/random.c
> +++ b/random.c
> @@ -42,6 +42,7 @@ static unsigned long randbits(int limit)
> static unsigned long taviso(void)
> {
> unsigned long r = 0;
> + unsigned long temp;
>
> switch (rand() % 4) {
> case 0: r = rand() & rand();
> @@ -51,10 +52,14 @@ static unsigned long taviso(void)
> #endif
> break;
>
> - case 1: r = rand() % rand();
> + case 1: temp = rand();
> + r = rand();
> + if (!temp) r %= temp;
> #if __WORDSIZE == 64
> r <<= 32;
> - r |= rand() % rand();
> +
> + temp = rand();
> + if (!temp) r |= rand() % temp;
> #endif
> break;
Good catch. Despite the function name, this is something I introduced,
not something that was in Tavis' original code in iknowthis.
Mea culpa.
Dave
next prev parent reply other threads:[~2014-01-17 21:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-17 20:21 divide by zero in random/taviso() Vince Weaver
2014-01-17 20:41 ` [patch] fix " Vince Weaver
2014-01-17 21:03 ` Dave Jones [this message]
[not found] ` <CAKB9nXvQmAU-PXjqbezf7G5bWfrjMTD5LjoFnj98K8Tyy5eQ2Q@mail.gmail.com>
2014-01-21 19:07 ` Dave Jones
2014-01-21 19:47 ` Vince Weaver
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140117210356.GA10744@redhat.com \
--to=davej@redhat.com \
--cc=trinity@vger.kernel.org \
--cc=vincent.weaver@maine.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox