git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Joachim Schmitz" <jojo@schmitz-digital.de>
To: git@vger.kernel.org
Subject: Re: [PATCH] Fix sizeof usage in get_permutations
Date: Thu, 13 Dec 2012 17:13:49 +0100	[thread overview]
Message-ID: <kacus2$mml$1@ger.gmane.org> (raw)
In-Reply-To: 1355405790-20302-1-git-send-email-mattjd@gmail.com

Matthew Daley wrote:
> Currently it gets the size of an otherwise unrelated, unused variable
> instead of the expected struct size.
> 
> Signed-off-by: Matthew Daley <mattjd@gmail.com>
> ---
> builtin/pack-redundant.c |    6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
> index f5c6afc..7544687 100644
> --- a/builtin/pack-redundant.c
> +++ b/builtin/pack-redundant.c
> @@ -301,14 +301,14 @@ static void pll_free(struct pll *l)
>  */
> static struct pll * get_permutations(struct pack_list *list, int n)
> {
> - struct pll *subset, *ret = NULL, *new_pll = NULL, *pll;
> + struct pll *subset, *ret = NULL, *new_pll = NULL;
> 
>  if (list == NULL || pack_list_size(list) < n || n == 0)
>  return NULL;
> 
>  if (n == 1) {
>  while (list) {
> - new_pll = xmalloc(sizeof(pll));
> + new_pll = xmalloc(sizeof(struct pll));
>  new_pll->pl = NULL;
>  pack_list_insert(&new_pll->pl, list);
>  new_pll->next = ret;
> @@ -321,7 +321,7 @@ static struct pll * get_permutations(struct
>  pack_list *list, int n) while (list->next) {
>  subset = get_permutations(list->next, n - 1);
>  while (subset) {
> - new_pll = xmalloc(sizeof(pll));
> + new_pll = xmalloc(sizeof(struct pll));

Why not just
new_pll = xmalloc(sizeof(*new_pll));

>  new_pll->pl = subset->pl;
>  pack_list_insert(&new_pll->pl, list);
>  new_pll->next = ret;

  reply	other threads:[~2012-12-13 16:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-13 13:36 [PATCH] Fix sizeof usage in get_permutations Matthew Daley
2012-12-13 16:13 ` Joachim Schmitz [this message]
2012-12-13 22:09   ` Felipe Contreras
2012-12-13 19:11 ` 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='kacus2$mml$1@ger.gmane.org' \
    --to=jojo@schmitz-digital.de \
    --cc=git@vger.kernel.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 NNTP newsgroup(s).