bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 5/6] stdlibc: Simplify realpath via scratch_buffer_dupfree


From: Adhemerval Zanella
Subject: [PATCH v2 5/6] stdlibc: Simplify realpath via scratch_buffer_dupfree
Date: Mon, 28 Dec 2020 10:59:43 -0300

From: Paul Eggert <eggert@cs.ucla.edu>

Checked on x86_64-linux-gnu.
---
 stdlib/canonicalize.c | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)

diff --git a/stdlib/canonicalize.c b/stdlib/canonicalize.c
index 24a027b83f..69f978da78 100644
--- a/stdlib/canonicalize.c
+++ b/stdlib/canonicalize.c
@@ -414,24 +414,14 @@ error:
 error_nomem:
   scratch_buffer_free (&extra_buffer);
   scratch_buffer_free (&link_buffer);
-  if (failed || rname == resolved)
-    scratch_buffer_free (rname_buf);
-
-  if (failed)
-    return NULL;
 
-  if (rname == resolved)
-    return rname;
-  idx_t rname_size = dest - rname;
-  if (rname == rname_on_stack)
+  if (failed || rname == resolved)
     {
-      rname = malloc (rname_size);
-      if (rname == NULL)
-        return NULL;
-      return memcpy (rname, rname_on_stack, rname_size);
+      scratch_buffer_free (rname_buf);
+      return failed ? NULL : resolved;
     }
-  char *result = realloc (rname, rname_size);
-  return result != NULL ? result : rname;
+
+  return scratch_buffer_dupfree (rname_buf, dest - rname);
 }
 
 /* Return the canonical absolute name of file NAME.  A canonical name
-- 
2.25.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]