This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

libiberty/getcwd.c, null argument patch (and fixincl)


The files gcc/fixinc/fixincl.c and gcc/fixinc/server.c rely on the
mallocing behaviour of getcwd when passed a null argument for the buffer,
but the compatibility versions in the libiberty library do not support
this behaviour.

I've provided code to extend the libiberty library to support this
behaviour, but for maximum portability, I would recommend that the
maintainer of fixincl not depend on this behaviour because some getcwd
implementations may not support it.

    Melissa.

Enc.

--- getcwd.c.orig	Fri May 15 16:42:36 1998
+++ getcwd.c	Sat May 22 20:14:58 1999
@@ -13,8 +13,11 @@
 	the supplied buffer and return a pointer to the buffer.  If the
 	current directory's path doesn't fit in LEN characters, the result
 	is NULL and errno is set.

+	If pathname is a null pointer, getcwd() will obtain size bytes of
+	space using malloc.
+
 BUGS
 	Emulated via the getwd() call, which is reasonable for most
 	systems that do not have getcwd().

@@ -46,8 +49,15 @@
   if (result) {
     if (strlen (ourbuf) >= len) {
       errno = ERANGE;
       return 0;
+    }
+    if (!buf) {
+       buf = (char*)malloc(len);
+       if (!buf) {
+           errno = ENOMEM;
+	   return 0;
+       }
     }
     strcpy (buf, ourbuf);
   }
   return buf;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]