Bug 13720 - gcc/libjava/java/lang/natSystem.cc: syntax error using "unsigned jint"
Summary: gcc/libjava/java/lang/natSystem.cc: syntax error using "unsigned jint"
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libgcj (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: 17574
  Show dependency treegraph
 
Reported: 2004-01-17 15:21 UTC by Roland Illig
Modified: 2004-09-22 21:50 UTC (History)
2 users (show)

See Also:
Host: i686-debian-linux-gnu
Target: i686-debian-linux-gnu
Build: i686-debian-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2004-04-17 05:47:06


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Roland Illig 2004-01-17 15:21:22 UTC
Hello,

I tried to compile libjava to try out the GDK/GTK awt peer. When compiling with
gcc-3.3.3, i got a syntax error in `array_copy', where the source code is:

    ... if ((unsigned jint) src_offset ...

jint is typedef'd to __java_int and so there are two ID tokens in the
parentheses, not one type-ID. Maybe gcc-3.4 can handle this, but I would rather
apply this patch:

Index: natSystem.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/java/lang/natSystem.cc,v
retrieving revision 1.56
diff -u -r1.56 natSystem.cc
--- natSystem.cc        23 Jul 2003 15:31:43 -0000      1.56
+++ natSystem.cc        17 Jan 2004 15:20:27 -0000
@@ -66,10 +66,12 @@
   __JArray *src_a = (__JArray *) src;
   __JArray *dst_a = (__JArray *) dst;
   if (src_offset < 0 || dst_offset < 0 || count < 0
-      || (unsigned jint) src_offset > (unsigned jint) src_a->length
-      || (unsigned jint) (src_offset + count) > (unsigned jint) src_a->length
-      || (unsigned jint) dst_offset > (unsigned jint) dst_a->length
-      || (unsigned jint) (dst_offset + count) > (unsigned jint) dst_a->length)
+      || src_offset > src_a->length
+      || src_offset - (-count) >= 0 // check for possible integer overflow
+      || src_offset + count > src_a->length
+      || dst_offset > dst_a->length
+      || dst_offset - (-count) >= 0 // check for possible integer overflow
+      || dst_offset + count > dst_a->length)
     throw new ArrayIndexOutOfBoundsException;
 
   // Do-nothing cases.
Comment 1 Andrew Pinski 2004-01-17 17:46:54 UTC
Confirmed, always send java patches to both gcc-patches@gcc.gnu.org and java-
patches@gcc.gnu.org with a changelog.
Comment 2 Tom Tromey 2004-09-22 21:50:14 UTC
A couple notes on this patch.

First, we don't support compiling libgcj with a different
version of gcj other than the one it comes with.  The reason
for this is that gcj and libgcj are tightly coupled; for instance
gcj and libgcj both have information about the exact format of
java.lang.Class.

Second, I'm not sure this patch is correct.  E.g.,

+      || src_offset - (-count) >= 0 // check for possible integer overflow

Suppose src_offset==10 and count==3.
Then src_offset-(-count) == 7, which is >= 0,
but no integer overflow has occurred.
(This is a perfectly valid situation if the source
array's length is >= 13)

So, I'm closing this and not checking in the patch.