git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix sizeof usage in get_permutations
@ 2012-12-13 13:36 Matthew Daley
  2012-12-13 16:13 ` Joachim Schmitz
  2012-12-13 19:11 ` Junio C Hamano
  0 siblings, 2 replies; 4+ messages in thread
From: Matthew Daley @ 2012-12-13 13:36 UTC (permalink / raw)
  To: git; +Cc: Matthew Daley

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));
 			new_pll->pl = subset->pl;
 			pack_list_insert(&new_pll->pl, list);
 			new_pll->next = ret;
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix sizeof usage in get_permutations
  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
  2012-12-13 19:11 ` Junio C Hamano
  1 sibling, 1 reply; 4+ messages in thread
From: Joachim Schmitz @ 2012-12-13 16:13 UTC (permalink / raw)
  To: git

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;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix sizeof usage in get_permutations
  2012-12-13 13:36 [PATCH] Fix sizeof usage in get_permutations Matthew Daley
  2012-12-13 16:13 ` Joachim Schmitz
@ 2012-12-13 19:11 ` Junio C Hamano
  1 sibling, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2012-12-13 19:11 UTC (permalink / raw)
  To: Matthew Daley; +Cc: git

Thanks; it shows how rarely this obscure tool is used these days.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix sizeof usage in get_permutations
  2012-12-13 16:13 ` Joachim Schmitz
@ 2012-12-13 22:09   ` Felipe Contreras
  0 siblings, 0 replies; 4+ messages in thread
From: Felipe Contreras @ 2012-12-13 22:09 UTC (permalink / raw)
  To: Joachim Schmitz; +Cc: git

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-12-13 22:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2012-12-13 19:11 ` Junio C Hamano

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).