Re: [PATCH 05/15] name-rev: use sizeof(*ptr) instead of sizeof(type) in allocation
- From
René Scharfe <l.s.r@web.de>
- Date
- Sep 20, 2019, 16:37 UTC
- Message-ID
- <afa53824-9d55-9a55-eb00-ead9ff9940ce@web.de>
- In-Reply-To
- <20190919214712.7348-6-szeder.dev@gmail.com>
Am 19.09.19 um 23:47 schrieb SZEDER Gábor:
Show 15 quoted lines
> Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
> ---
> builtin/name-rev.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/builtin/name-rev.c b/builtin/name-rev.c
> index e406ff8e17..dec2228cc7 100644
> --- a/builtin/name-rev.c
> +++ b/builtin/name-rev.c
> @@ -98,7 +98,7 @@ static void name_rev(struct commit *commit,
> }
>
> if (name == NULL) {
> - name = xmalloc(sizeof(rev_name));
> + name = xmalloc(sizeof(*name));Here are the declarations of both (and my beloved --function-context option would only have shown the second one):
typedef struct rev_name {
const char *tip_name;
timestamp_t taggerdate;
int generation;
int distance;
int from_tag;
} rev_name;struct rev_name *name = get_commit_rev_name(commit);
So your patch is correct. Had me scratching my head when I first saw it, though. That old code has been present since bd321bcc51 ("Add git-name-rev", 2005-10-26).
> set_commit_rev_name(commit, name);
> goto copy_data;
> } else if (is_better_name(name, taggerdate, distance, from_tag)) {
>