| Summary: | java.Random.nextInt(int) may return negative | ||
|---|---|---|---|
| Product: | gcc | Reporter: | svens |
| Component: | libgcj | Assignee: | Tom Tromey <tromey> |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | CC: | gcc-bugs, java-prs |
| Priority: | P3 | ||
| Version: | 3.2 | ||
| Target Milestone: | --- | ||
| Host: | Target: | ||
| Build: | Known to work: | ||
| Known to fail: | Last reconfirmed: | ||
| Attachments: | Test.java | ||
|
Description
svens
2002-11-06 09:46:02 UTC
Fix:
Here's a patch against a recent CVS:
Index: libjava/java/util/Random.java
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/util/Random.java,v
retrieving revision 1.7
diff -u -r1.7 Random.java
--- libjava/java/util/Random.java 18 Jun 2002 15:40:00 -0000 1.7
+++ libjava/java/util/Random.java 6 Nov 2002 16:55:16 -0000
@@ -296,7 +296,7 @@
int bits, val;
do
{
- bits = next(32);
+ bits = next(31);
val = bits % n;
}
while (bits - val + (n - 1) < 0);
Responsible-Changed-From-To: unassigned->tromey Responsible-Changed-Why: I'm handling this State-Changed-From-To: open->closed
State-Changed-Why: Thanks for the report and the patch.
I'm checking in your fix on the trunk.
I'm also putting it into Classpath.
I've added your test to Mauve.
From: tromey@gcc.gnu.org To: gcc-gnats@gcc.gnu.org Cc: Subject: libgcj/8481 Date: 7 Nov 2002 04:38:21 -0000 CVSROOT: /cvs/gcc Module name: gcc Changes by: tromey@gcc.gnu.org 2002-11-06 20:38:21 Modified files: libjava : ChangeLog libjava/java/util: Random.java Log message: From svens@it.uu.se. For PR libgcj/8481. * java/util/Random.java (nextInt(int)): Only use 31 bits. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&r1=1.1508&r2=1.1509 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/util/Random.java.diff?cvsroot=gcc&r1=1.7&r2=1.8 |