diff options
Diffstat (limited to 'sysdeps/posix')
-rw-r--r-- | sysdeps/posix/getcwd.c | 5 |
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; |