about summary refs log tree commit diff
path: root/sysdeps/posix/getcwd.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/posix/getcwd.c')
-rw-r--r--sysdeps/posix/getcwd.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/sysdeps/posix/getcwd.c b/sysdeps/posix/getcwd.c
index 825599f370..5f3f628fb5 100644
--- a/sysdeps/posix/getcwd.c
+++ b/sysdeps/posix/getcwd.c
@@ -344,8 +344,11 @@ __getcwd (buf, size)
 		      __set_errno (ENOMEM);/* closedir might have changed it.*/
 		      return NULL;
 		    }
-		  pathp = &buf[pathp - path];
+		  pathp = &buf[pathp - path + size / 2];
 		  path = buf;
+		  /* Move current contents up to the end of the buffer.
+		     This is guaranteed to be non-overlapping.  */
+		  memcpy (pathp, pathp - size / 2, path + size - pathp);
 		}
 	    }
 	  pathp -= namlen;