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

Re: [PATCH] Fix sizeof usage in get_permutations

From
Joachim Schmitz <jojo@schmitz-digital.de>
Date
Dec 13, 2012, 16:13 UTC
Message-ID
<kacus2$mml$1@ger.gmane.org>
In-Reply-To
<1355405790-20302-1-git-send-email-mattjd@gmail.com>
Matthew Daley wrote:
Show 35 quoted lines
> 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;
Previous: Matthew DaleyNext: Felipe Contreras
Message 2 of 4 in “Fix sizeof usage in get_permutations”
  1. Fix sizeof usage in get_permutationsMatthew Daley, Dec 13, 2012
  2. Joachim SchmitzDec 13, 2012
  3. Felipe ContrerasDec 13, 2012
  4. Junio C HamanoDec 13, 2012

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.