git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: Joachim Schmitz <jojo@schmitz-digital.de>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] Fix sizeof usage in get_permutations
Date: Thu, 13 Dec 2012 16:09:53 -0600	[thread overview]
Message-ID: <CAMP44s06jjsxKVk_fVb7dadiZ=d2XavrLT2DRhqOPG2XwmcoMQ@mail.gmail.com> (raw)
In-Reply-To: <kacus2$mml$1@ger.gmane.org>

On Thu, Dec 13, 2012 at 10:13 AM, Joachim Schmitz
<jojo@schmitz-digital.de> wrote:
> 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));

I prefer that one; it's Linux kernel style.

-- 
Felipe Contreras

  reply	other threads:[~2012-12-13 22:10 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
2012-12-13 22:09   ` Felipe Contreras [this message]
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='CAMP44s06jjsxKVk_fVb7dadiZ=d2XavrLT2DRhqOPG2XwmcoMQ@mail.gmail.com' \
    --to=felipe.contreras@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jojo@schmitz-digital.de \
    /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).