From: Eric Sunshine <sunshine@sunshineco.com>
To: Stefan Beller <sbeller@google.com>
Cc: Jeff King <peff@peff.net>, Git List <git@vger.kernel.org>,
Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] prefix_path(): Unconditionally free result of prefix_path
Date: Mon, 4 May 2015 16:19:26 -0400 [thread overview]
Message-ID: <CAPig+cSuCouNCuKa99mct4UMPykuMVy3+7sqB6y+v+UtP2oeTw@mail.gmail.com> (raw)
In-Reply-To: <1430766714-22368-1-git-send-email-sbeller@google.com>
On Mon, May 4, 2015 at 3:11 PM, Stefan Beller <sbeller@google.com> wrote:
> prefix_path(): Unconditionally free result of prefix_path
Slightly redundant mention of "prefix_path". Also, prevailing custom
is to drop capitalization.
> prefix_path() always returns a newly allocated string since
> d089eba (setup: sanitize absolute and funny paths in get_pathspec(),
> 2008-01-28)
I'd probably turn this sentence fragment into a proper sentence:
As of d089eba (...), prefix_path() always returns a newly
allocated string, so free its result unconditionally.
> Additionally the const is dropped from the pointers, so the call to
> free doesn't need a cast.
Imperative mood:
Additionally, drop the const from variables to which the
prefix_path() result is assigned so they can be free()'d
without having to cast-away constness.
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
>
> Notes:
> Thanks for all the suggestions!
> They are incorporated into this version of the patch.
Thanks, this version looks much better.
FWIW, with or without addressing the very minor nits above:
Reviewed-by: Eric Sunshine <sunshine@sunshineco.com>
> diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
> index 9ca2da1..8028c37 100644
> --- a/builtin/checkout-index.c
> +++ b/builtin/checkout-index.c
> @@ -241,7 +241,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
> /* Check out named files first */
> for (i = 0; i < argc; i++) {
> const char *arg = argv[i];
> - const char *p;
> + char *p;
>
> if (all)
> die("git checkout-index: don't mix '--all' and explicit filenames");
> @@ -249,8 +249,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
> die("git checkout-index: don't mix '--stdin' and explicit filenames");
> p = prefix_path(prefix, prefix_length, arg);
> checkout_file(p, prefix);
> - if (p < arg || p > arg + strlen(arg))
> - free((char *)p);
> + free(p);
> }
>
> if (read_from_stdin) {
> @@ -260,7 +259,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
> die("git checkout-index: don't mix '--all' and '--stdin'");
>
> while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
> - const char *p;
> + char *p;
> if (line_termination && buf.buf[0] == '"') {
> strbuf_reset(&nbuf);
> if (unquote_c_style(&nbuf, buf.buf, NULL))
> @@ -269,8 +268,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
> }
> p = prefix_path(prefix, prefix_length, buf.buf);
> checkout_file(p, prefix);
> - if (p < buf.buf || p > buf.buf + buf.len)
> - free((char *)p);
> + free(p);
> }
> strbuf_release(&nbuf);
> strbuf_release(&buf);
> diff --git a/builtin/update-index.c b/builtin/update-index.c
> index 6271b54..a92eed2 100644
> --- a/builtin/update-index.c
> +++ b/builtin/update-index.c
> @@ -532,10 +532,9 @@ static int do_unresolve(int ac, const char **av,
>
> for (i = 1; i < ac; i++) {
> const char *arg = av[i];
> - const char *p = prefix_path(prefix, prefix_length, arg);
> + char *p = prefix_path(prefix, prefix_length, arg);
> err |= unresolve_one(p);
> - if (p < arg || p > arg + strlen(arg))
> - free((char *)p);
> + free(p);
> }
> return err;
> }
> --
> 2.4.0.rc3.16.g0ab00b9
next prev parent reply other threads:[~2015-05-04 20:19 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-04 19:11 [PATCH] prefix_path(): Unconditionally free result of prefix_path Stefan Beller
2015-05-04 20:19 ` Eric Sunshine [this message]
2015-05-04 22:29 ` Junio C Hamano
2015-05-05 3:21 ` Jeff King
2015-05-05 16:28 ` Stefan Beller
2015-05-05 17:36 ` Junio C Hamano
2015-05-05 17:56 ` Jeff King
2015-05-05 18:09 ` Junio C Hamano
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAPig+cSuCouNCuKa99mct4UMPykuMVy3+7sqB6y+v+UtP2oeTw@mail.gmail.com \
--to=sunshine@sunshineco.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
--cc=sbeller@google.com \
/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 NNTP newsgroup(s).