]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
(__getcwd): Use temporary variable to store result of realloc instead
authorUlrich Drepper <drepper@redhat.com>
Mon, 5 Oct 1998 10:59:18 +0000 (10:59 +0000)
committerUlrich Drepper <drepper@redhat.com>
Mon, 5 Oct 1998 10:59:18 +0000 (10:59 +0000)
of using BUF.

sysdeps/posix/getcwd.c

index 865bd3fa6a11e8b92ee8d780beee7b7ec75aa5fe..21b3fabade30a158efdf0bd8b456fbfb3b139237 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
+/* Copyright (C) 1991,92,93,94,95,96,97,98 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -336,17 +336,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);