re PR libgcj/6652 (new java.io.File("").getCanonicalFile() throws exception)
authorTom Tromey <tromey@redhat.com>
Wed, 12 Jun 2002 17:01:02 +0000 (17:01 +0000)
committerTom Tromey <tromey@gcc.gnu.org>
Wed, 12 Jun 2002 17:01:02 +0000 (17:01 +0000)
* java/io/natFilePosix.cc (getCanonicalPath): Treat "" like ".".
Fixes PR libgcj/6652.

From-SVN: r54558

libjava/ChangeLog
libjava/java/io/natFilePosix.cc

index 072c7b56945a784f15b1ecc411528131a109713a..26bd707ec6c81562af587541cde77538fcec05f6 100644 (file)
@@ -1,3 +1,8 @@
+2002-06-12  Tom Tromey  <tromey@redhat.com>
+
+       * java/io/natFilePosix.cc (getCanonicalPath): Treat "" like ".".
+       Fixes PR libgcj/6652.
+
 2002-06-10  Tom Tromey  <tromey@redhat.com>
 
        * java/lang/Class.h (Class::desiredAssertionStatus): Declare.
index cd04571b04e4aed59fe9bc067a9899677bcd637a..f9fe78ef203c212bb562667e90618f816b736484 100644 (file)
@@ -104,9 +104,16 @@ java::io::File::attr (jint query)
 jstring
 java::io::File::getCanonicalPath (void)
 {
-  char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (path) + 1);
+  // We use `+2' here because we might need to use `.' for our special
+  // case.
+  char *buf = (char *) __builtin_alloca (JvGetStringUTFLength (path) + 2);
   char buf2[MAXPATHLEN];
   jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf);
+
+  // Special case: treat "" the same as ".".
+  if (total == 0)
+    buf[total++] = '.';
+
   buf[total] = '\0';
 
 #ifdef HAVE_REALPATH