{"thread":{"id":"32330","subject":"[PATCH] Fix sizeof usage in get_permutations","startedAt":"2012-12-13T13:36:30Z","lastAt":"2012-12-13T22:09:53Z","messageCount":4,"participants":["Matthew Daley","Joachim Schmitz","Junio C Hamano","Felipe Contreras"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"204833","messageId":"1355405790-20302-1-git-send-email-mattjd@gmail.com","threadId":"32330","inReplyTo":null,"subject":"[PATCH] Fix sizeof usage in get_permutations","fromName":"Matthew Daley","fromEmail":"mattjd@gmail.com","sentAt":"2012-12-13T13:36:30Z","receivedAt":"2012-12-13T13:36:30Z","isPatch":true,"sender":{"key":"mattjd@gmail.com","avatar":null},"body":"Currently it gets the size of an otherwise unrelated, unused variable\ninstead of the expected struct size.\n\nSigned-off-by: Matthew Daley <mattjd@gmail.com>\n---\n builtin/pack-redundant.c |    6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c\nindex f5c6afc..7544687 100644\n--- a/builtin/pack-redundant.c\n+++ b/builtin/pack-redundant.c\n@@ -301,14 +301,14 @@ static void pll_free(struct pll *l)\n  */\n static struct pll * get_permutations(struct pack_list *list, int n)\n {\n-\tstruct pll *subset, *ret = NULL, *new_pll = NULL, *pll;\n+\tstruct pll *subset, *ret = NULL, *new_pll = NULL;\n \n \tif (list == NULL || pack_list_size(list) < n || n == 0)\n \t\treturn NULL;\n \n \tif (n == 1) {\n \t\twhile (list) {\n-\t\t\tnew_pll = xmalloc(sizeof(pll));\n+\t\t\tnew_pll = xmalloc(sizeof(struct pll));\n \t\t\tnew_pll->pl = NULL;\n \t\t\tpack_list_insert(&new_pll->pl, list);\n \t\t\tnew_pll->next = ret;\n@@ -321,7 +321,7 @@ static struct pll * get_permutations(struct pack_list *list, int n)\n \twhile (list->next) {\n \t\tsubset = get_permutations(list->next, n - 1);\n \t\twhile (subset) {\n-\t\t\tnew_pll = xmalloc(sizeof(pll));\n+\t\t\tnew_pll = xmalloc(sizeof(struct pll));\n \t\t\tnew_pll->pl = subset->pl;\n \t\t\tpack_list_insert(&new_pll->pl, list);\n \t\t\tnew_pll->next = ret;\n-- \n1.7.10.4\n"},{"id":"204837","messageId":"kacus2$mml$1@ger.gmane.org","threadId":"32330","inReplyTo":"1355405790-20302-1-git-send-email-mattjd@gmail.com","subject":"Re: [PATCH] Fix sizeof usage in get_permutations","fromName":"Joachim Schmitz","fromEmail":"jojo@schmitz-digital.de","sentAt":"2012-12-13T16:13:49Z","receivedAt":"2012-12-13T16:13:49Z","isPatch":true,"sender":{"key":"jojo@schmitz-digital.de","avatar":"https://avatars.githubusercontent.com/u/1786669?v=4"},"body":"Matthew Daley wrote:\n> Currently it gets the size of an otherwise unrelated, unused variable\n> instead of the expected struct size.\n> \n> Signed-off-by: Matthew Daley <mattjd@gmail.com>\n> ---\n> builtin/pack-redundant.c |    6 +++---\n> 1 file changed, 3 insertions(+), 3 deletions(-)\n> \n> diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c\n> index f5c6afc..7544687 100644\n> --- a/builtin/pack-redundant.c\n> +++ b/builtin/pack-redundant.c\n> @@ -301,14 +301,14 @@ static void pll_free(struct pll *l)\n>  */\n> static struct pll * get_permutations(struct pack_list *list, int n)\n> {\n> - struct pll *subset, *ret = NULL, *new_pll = NULL, *pll;\n> + struct pll *subset, *ret = NULL, *new_pll = NULL;\n> \n>  if (list == NULL || pack_list_size(list) < n || n == 0)\n>  return NULL;\n> \n>  if (n == 1) {\n>  while (list) {\n> - new_pll = xmalloc(sizeof(pll));\n> + new_pll = xmalloc(sizeof(struct pll));\n>  new_pll->pl = NULL;\n>  pack_list_insert(&new_pll->pl, list);\n>  new_pll->next = ret;\n> @@ -321,7 +321,7 @@ static struct pll * get_permutations(struct\n>  pack_list *list, int n) while (list->next) {\n>  subset = get_permutations(list->next, n - 1);\n>  while (subset) {\n> - new_pll = xmalloc(sizeof(pll));\n> + new_pll = xmalloc(sizeof(struct pll));\n\nWhy not just\nnew_pll = xmalloc(sizeof(*new_pll));\n\n>  new_pll->pl = subset->pl;\n>  pack_list_insert(&new_pll->pl, list);\n>  new_pll->next = ret;\n"},{"id":"204848","messageId":"7vtxrpydfw.fsf@alter.siamese.dyndns.org","threadId":"32330","inReplyTo":"1355405790-20302-1-git-send-email-mattjd@gmail.com","subject":"Re: [PATCH] Fix sizeof usage in get_permutations","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-12-13T19:11:47Z","receivedAt":"2012-12-13T19:11:47Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks; it shows how rarely this obscure tool is used these days.\n"},{"id":"204855","messageId":"CAMP44s06jjsxKVk_fVb7dadiZ=d2XavrLT2DRhqOPG2XwmcoMQ@mail.gmail.com","threadId":"32330","inReplyTo":"kacus2$mml$1@ger.gmane.org","subject":"Re: [PATCH] Fix sizeof usage in get_permutations","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-12-13T22:09:53Z","receivedAt":"2012-12-13T22:09:53Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Thu, Dec 13, 2012 at 10:13 AM, Joachim Schmitz\n<jojo@schmitz-digital.de> wrote:\n> Matthew Daley wrote:\n>>\n>> Currently it gets the size of an otherwise unrelated, unused variable\n>> instead of the expected struct size.\n>>\n>> Signed-off-by: Matthew Daley <mattjd@gmail.com>\n>> ---\n>> builtin/pack-redundant.c |    6 +++---\n>> 1 file changed, 3 insertions(+), 3 deletions(-)\n>>\n>> diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c\n>> index f5c6afc..7544687 100644\n>> --- a/builtin/pack-redundant.c\n>> +++ b/builtin/pack-redundant.c\n>> @@ -301,14 +301,14 @@ static void pll_free(struct pll *l)\n>>  */\n>> static struct pll * get_permutations(struct pack_list *list, int n)\n>> {\n>> - struct pll *subset, *ret = NULL, *new_pll = NULL, *pll;\n>> + struct pll *subset, *ret = NULL, *new_pll = NULL;\n>>\n>>  if (list == NULL || pack_list_size(list) < n || n == 0)\n>>  return NULL;\n>>\n>>  if (n == 1) {\n>>  while (list) {\n>> - new_pll = xmalloc(sizeof(pll));\n>> + new_pll = xmalloc(sizeof(struct pll));\n>>  new_pll->pl = NULL;\n>>  pack_list_insert(&new_pll->pl, list);\n>>  new_pll->next = ret;\n>> @@ -321,7 +321,7 @@ static struct pll * get_permutations(struct\n>>  pack_list *list, int n) while (list->next) {\n>>  subset = get_permutations(list->next, n - 1);\n>>  while (subset) {\n>> - new_pll = xmalloc(sizeof(pll));\n>> + new_pll = xmalloc(sizeof(struct pll));\n>\n>\n> Why not just\n> new_pll = xmalloc(sizeof(*new_pll));\n\nI prefer that one; it's Linux kernel style.\n\n-- \nFelipe Contreras\n"}]}