bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org, Paul Eggert <eggert@cs.ucla.edu>
Cc: bug-gnulib@gnu.org
Subject: [PATCH v2 5/6] stdlibc: Simplify realpath via scratch_buffer_dupfree
Date: Mon, 28 Dec 2020 10:59:43 -0300	[thread overview]
Message-ID: <20201228135944.1018303-5-adhemerval.zanella@linaro.org> (raw)
In-Reply-To: <20201228135944.1018303-1-adhemerval.zanella@linaro.org>

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



  parent reply	other threads:[~2020-12-28 14:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-28 13:59 [PATCH v2 1/6] Import idx.h from gnulib Adhemerval Zanella
2020-12-28 13:59 ` [PATCH v2 2/6] Import filename.h " Adhemerval Zanella
2020-12-28 13:59 ` [PATCH v2 3/6] malloc: Add scratch_buffer_dupfree Adhemerval Zanella
2020-12-28 13:59 ` [PATCH v2 4/6] stdlib: Sync canonicalize with gnulib [BZ #10635] [BZ #26592] [BZ #26341] [BZ #24970] Adhemerval Zanella
2020-12-28 21:07   ` Paul Eggert
2020-12-28 13:59 ` Adhemerval Zanella [this message]
2020-12-28 13:59 ` [PATCH v2 6/6] stdlib: Assume FACCESSAT_NEVER_EOVERFLOWS on realpath Adhemerval Zanella
2020-12-28 21:14   ` Paul Eggert
2020-12-28 21:50     ` Adhemerval Zanella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201228135944.1018303-5-adhemerval.zanella@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=bug-gnulib@gnu.org \
    --cc=eggert@cs.ucla.edu \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).