diff options
Diffstat (limited to 'sysdeps/posix/getcwd.c')
-rw-r--r-- | sysdeps/posix/getcwd.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/sysdeps/posix/getcwd.c b/sysdeps/posix/getcwd.c index 551fa7241e..7de5fd3a75 100644 --- a/sysdeps/posix/getcwd.c +++ b/sysdeps/posix/getcwd.c @@ -369,17 +369,19 @@ __getcwd (buf, size) } else { + char *tmp; + size *= 2; - buf = realloc (path, size); - if (buf == NULL) + tmp = realloc (path, size); + if (tmp == NULL) { (void) __closedir (dirstream); free (path); __set_errno (ENOMEM);/* closedir might have changed it.*/ goto lose; } - pathp = &buf[pathp - path + size / 2]; - path = buf; + pathp = &tmp[pathp - path + size / 2]; + path = tmp; /* 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); |