aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sh/getcwd.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sh/getcwd.c')
-rw-r--r--lib/sh/getcwd.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/sh/getcwd.c b/lib/sh/getcwd.c
index cd724f6..1a02794 100644
--- a/lib/sh/getcwd.c
+++ b/lib/sh/getcwd.c
@@ -251,19 +251,21 @@ getcwd (buf, size)
{
size_t len = pathbuf + pathsize - pathp;
+ if (buf == NULL && size <= 0)
+ size = len;
+
+ if ((size_t) size < len)
+ {
+ errno = ERANGE;
+ goto lose2;
+ }
if (buf == NULL)
{
- if (len < (size_t) size)
- len = size;
- buf = (char *) malloc (len);
+ buf = (char *) malloc (size);
if (buf == NULL)
goto lose2;
}
- else if ((size_t) size < len)
- {
- errno = ERANGE;
- goto lose2;
- }
+
(void) memcpy((PTR_T) buf, (PTR_T) pathp, len);
}