git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] prefix_path(): Unconditionally free result of prefix_path

From
Eric Sunshine <sunshine@sunshineco.com>
Date
May 4, 2015, 20:19 UTC
Message-ID
<CAPig+cSuCouNCuKa99mct4UMPykuMVy3+7sqB6y+v+UtP2oeTw@mail.gmail.com>
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.
Show 6 quoted lines
> 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>
Show 61 quoted lines
> 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
Previous: Stefan BellerNext: Junio C Hamano
Message 2 of 8 in “prefix_path(): Unconditionally free result of prefix_path”
  1. prefix_path(): Unconditionally free result of prefix_pathStefan Beller, May 4, 2015
  2. Eric SunshineMay 4, 2015
  3. Junio C HamanoMay 4, 2015
  4. Jeff KingMay 5, 2015
  5. Stefan BellerMay 5, 2015
  6. Junio C HamanoMay 5, 2015
  7. Jeff KingMay 5, 2015
  8. Junio C HamanoMay 5, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.