{"thread":{"id":"37449","subject":"[PATCH] fix calloc() and xcalloc() argument ordering","startedAt":"2014-08-30T06:54:23Z","lastAt":"2014-09-04T14:03:15Z","messageCount":4,"participants":["Arjun Sreedharan","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"248606","messageId":"1409381663-9532-1-git-send-email-arjun024@gmail.com","threadId":"37449","inReplyTo":null,"subject":"[PATCH] fix calloc() and xcalloc() argument ordering","fromName":"Arjun Sreedharan","fromEmail":"arjun024@gmail.com","sentAt":"2014-08-30T06:54:23Z","receivedAt":"2014-08-30T06:54:23Z","isPatch":true,"sender":{"key":"arjun024@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2861611?v=4"},"body":"@number first, @size second argument.\n\nSigned-off-by: Arjun Sreedharan <arjun024@gmail.com>\n---\n builtin/for-each-ref.c        |  2 +-\n compat/regex/regcomp.c        | 12 ++++++------\n compat/regex/regex_internal.c |  4 ++--\n compat/regex/regexec.c        | 10 +++++-----\n imap-send.c                   |  2 +-\n 5 files changed, 15 insertions(+), 15 deletions(-)\n\ndiff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c\nindex 47bd624..69bba06 100644\n--- a/builtin/for-each-ref.c\n+++ b/builtin/for-each-ref.c\n@@ -633,7 +633,7 @@ static void populate_value(struct refinfo *ref)\n \tunsigned long size;\n \tconst unsigned char *tagged;\n \n-\tref->value = xcalloc(sizeof(struct atom_value), used_atom_cnt);\n+\tref->value = xcalloc(used_atom_cnt, sizeof(struct atom_value));\n \n \tif (need_symref && (ref->flag & REF_ISSYMREF) && !ref->symref) {\n \t\tunsigned char unused1[20];\ndiff --git a/compat/regex/regcomp.c b/compat/regex/regcomp.c\nindex 06f3088..e375c50 100644\n--- a/compat/regex/regcomp.c\n+++ b/compat/regex/regcomp.c\n@@ -861,7 +861,7 @@ init_dfa (re_dfa_t *dfa, size_t pat_len)\n     if (table_size > pat_len)\n       break;\n \n-  dfa->state_table = calloc (sizeof (struct re_state_table_entry), table_size);\n+  dfa->state_table = calloc (table_size, sizeof (struct re_state_table_entry));\n   dfa->state_hash_mask = table_size - 1;\n \n   dfa->mb_cur_max = MB_CUR_MAX;\n@@ -929,7 +929,7 @@ init_dfa (re_dfa_t *dfa, size_t pat_len)\n \t{\n \t  int i, j, ch;\n \n-\t  dfa->sb_char = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);\n+\t  dfa->sb_char = (re_bitset_ptr_t) calloc (1, sizeof (bitset_t));\n \t  if (BE (dfa->sb_char == NULL, 0))\n \t    return REG_ESPACE;\n \n@@ -3072,9 +3072,9 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,\n \t\t\t\t\t\t   _NL_COLLATE_SYMB_EXTRAMB);\n     }\n #endif\n-  sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);\n+  sbcset = (re_bitset_ptr_t) calloc (1, sizeof (bitset_t));\n #ifdef RE_ENABLE_I18N\n-  mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);\n+  mbcset = (re_charset_t *) calloc (1, sizeof (re_charset_t));\n #endif /* RE_ENABLE_I18N */\n #ifdef RE_ENABLE_I18N\n   if (BE (sbcset == NULL || mbcset == NULL, 0))\n@@ -3619,9 +3619,9 @@ build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans,\n   re_token_t br_token;\n   bin_tree_t *tree;\n \n-  sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);\n+  sbcset = (re_bitset_ptr_t) calloc (1, sizeof (bitset_t));\n #ifdef RE_ENABLE_I18N\n-  mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);\n+  mbcset = (re_charset_t *) calloc (1, sizeof (re_charset_t));\n #endif /* RE_ENABLE_I18N */\n \n #ifdef RE_ENABLE_I18N\ndiff --git a/compat/regex/regex_internal.c b/compat/regex/regex_internal.c\nindex d4121f2..9d9e986 100644\n--- a/compat/regex/regex_internal.c\n+++ b/compat/regex/regex_internal.c\n@@ -1629,7 +1629,7 @@ create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes,\n   reg_errcode_t err;\n   re_dfastate_t *newstate;\n \n-  newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1);\n+  newstate = (re_dfastate_t *) calloc (1, sizeof (re_dfastate_t));\n   if (BE (newstate == NULL, 0))\n     return NULL;\n   err = re_node_set_init_copy (&newstate->nodes, nodes);\n@@ -1679,7 +1679,7 @@ create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,\n   reg_errcode_t err;\n   re_dfastate_t *newstate;\n \n-  newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1);\n+  newstate = (re_dfastate_t *) calloc (1, sizeof (re_dfastate_t));\n   if (BE (newstate == NULL, 0))\n     return NULL;\n   err = re_node_set_init_copy (&newstate->nodes, nodes);\ndiff --git a/compat/regex/regexec.c b/compat/regex/regexec.c\nindex eb5e1d4..edfe0c6 100644\n--- a/compat/regex/regexec.c\n+++ b/compat/regex/regexec.c\n@@ -2797,8 +2797,8 @@ get_subexp (re_match_context_t *mctx, int bkref_node, int bkref_str_idx)\n \t    continue; /* No.  */\n \t  if (sub_top->path == NULL)\n \t    {\n-\t      sub_top->path = calloc (sizeof (state_array_t),\n-\t\t\t\t      sl_str - sub_top->str_idx + 1);\n+\t      sub_top->path = calloc (sl_str - sub_top->str_idx + 1,\n+\t\t\t\t      sizeof (state_array_t));\n \t      if (sub_top->path == NULL)\n \t\treturn REG_ESPACE;\n \t    }\n@@ -3362,7 +3362,7 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state)\n       if (ndests == 0)\n \t{\n \t  state->trtable = (re_dfastate_t **)\n-\t    calloc (sizeof (re_dfastate_t *), SBC_MAX);\n+\t    calloc (SBC_MAX, sizeof (re_dfastate_t *));\n \t  return 1;\n \t}\n       return 0;\n@@ -3458,7 +3458,7 @@ out_free:\n \t discern by looking at the character code: allocate a\n \t 256-entry transition table.  */\n       trtable = state->trtable =\n-\t(re_dfastate_t **) calloc (sizeof (re_dfastate_t *), SBC_MAX);\n+\t(re_dfastate_t **) calloc (SBC_MAX, sizeof (re_dfastate_t *));\n       if (BE (trtable == NULL, 0))\n \tgoto out_free;\n \n@@ -3489,7 +3489,7 @@ out_free:\n \t transition tables, one starting at trtable[0] and one\n \t starting at trtable[SBC_MAX].  */\n       trtable = state->word_trtable =\n-\t(re_dfastate_t **) calloc (sizeof (re_dfastate_t *), 2 * SBC_MAX);\n+\t(re_dfastate_t **) calloc (2 * SBC_MAX, sizeof (re_dfastate_t *));\n       if (BE (trtable == NULL, 0))\n \tgoto out_free;\n \ndiff --git a/imap-send.c b/imap-send.c\nindex 524fbab..02eb3e0 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -954,7 +954,7 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc)\n \n \tctx = xcalloc(1, sizeof(*ctx));\n \n-\tctx->imap = imap = xcalloc(sizeof(*imap), 1);\n+\tctx->imap = imap = xcalloc(1, sizeof(*imap));\n \timap->buf.sock.fd[0] = imap->buf.sock.fd[1] = -1;\n \timap->in_progress_append = &imap->in_progress;\n \n-- \n1.7.11.7\n"},{"id":"248727","messageId":"xmqqegvt27ac.fsf@gitster.dls.corp.google.com","threadId":"37449","inReplyTo":"1409381663-9532-1-git-send-email-arjun024@gmail.com","subject":"Re: [PATCH] fix calloc() and xcalloc() argument ordering","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-09-02T18:42:35Z","receivedAt":"2014-09-02T18:42:35Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Arjun Sreedharan <arjun024@gmail.com> writes:\n\n> @number first, @size second argument.\n>\n> Signed-off-by: Arjun Sreedharan <arjun024@gmail.com>\n> ---\n>  builtin/for-each-ref.c        |  2 +-\n\nThanks.  compat/regex/ being borrowed code, I'd prefer not to touch\nthem, though.\n\n>  compat/regex/regcomp.c        | 12 ++++++------\n>  compat/regex/regex_internal.c |  4 ++--\n>  compat/regex/regexec.c        | 10 +++++-----\n>  imap-send.c                   |  2 +-\n>  5 files changed, 15 insertions(+), 15 deletions(-)\n>\n> diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c\n> index 47bd624..69bba06 100644\n> --- a/builtin/for-each-ref.c\n> +++ b/builtin/for-each-ref.c\n> @@ -633,7 +633,7 @@ static void populate_value(struct refinfo *ref)\n>  \tunsigned long size;\n>  \tconst unsigned char *tagged;\n>  \n> -\tref->value = xcalloc(sizeof(struct atom_value), used_atom_cnt);\n> +\tref->value = xcalloc(used_atom_cnt, sizeof(struct atom_value));\n>  \n>  \tif (need_symref && (ref->flag & REF_ISSYMREF) && !ref->symref) {\n>  \t\tunsigned char unused1[20];\n> diff --git a/compat/regex/regcomp.c b/compat/regex/regcomp.c\n> index 06f3088..e375c50 100644\n> --- a/compat/regex/regcomp.c\n> +++ b/compat/regex/regcomp.c\n> @@ -861,7 +861,7 @@ init_dfa (re_dfa_t *dfa, size_t pat_len)\n>      if (table_size > pat_len)\n>        break;\n>  \n> -  dfa->state_table = calloc (sizeof (struct re_state_table_entry), table_size);\n> +  dfa->state_table = calloc (table_size, sizeof (struct re_state_table_entry));\n>    dfa->state_hash_mask = table_size - 1;\n>  \n>    dfa->mb_cur_max = MB_CUR_MAX;\n> @@ -929,7 +929,7 @@ init_dfa (re_dfa_t *dfa, size_t pat_len)\n>  \t{\n>  \t  int i, j, ch;\n>  \n> -\t  dfa->sb_char = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);\n> +\t  dfa->sb_char = (re_bitset_ptr_t) calloc (1, sizeof (bitset_t));\n>  \t  if (BE (dfa->sb_char == NULL, 0))\n>  \t    return REG_ESPACE;\n>  \n> @@ -3072,9 +3072,9 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,\n>  \t\t\t\t\t\t   _NL_COLLATE_SYMB_EXTRAMB);\n>      }\n>  #endif\n> -  sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);\n> +  sbcset = (re_bitset_ptr_t) calloc (1, sizeof (bitset_t));\n>  #ifdef RE_ENABLE_I18N\n> -  mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);\n> +  mbcset = (re_charset_t *) calloc (1, sizeof (re_charset_t));\n>  #endif /* RE_ENABLE_I18N */\n>  #ifdef RE_ENABLE_I18N\n>    if (BE (sbcset == NULL || mbcset == NULL, 0))\n> @@ -3619,9 +3619,9 @@ build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans,\n>    re_token_t br_token;\n>    bin_tree_t *tree;\n>  \n> -  sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);\n> +  sbcset = (re_bitset_ptr_t) calloc (1, sizeof (bitset_t));\n>  #ifdef RE_ENABLE_I18N\n> -  mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);\n> +  mbcset = (re_charset_t *) calloc (1, sizeof (re_charset_t));\n>  #endif /* RE_ENABLE_I18N */\n>  \n>  #ifdef RE_ENABLE_I18N\n> diff --git a/compat/regex/regex_internal.c b/compat/regex/regex_internal.c\n> index d4121f2..9d9e986 100644\n> --- a/compat/regex/regex_internal.c\n> +++ b/compat/regex/regex_internal.c\n> @@ -1629,7 +1629,7 @@ create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes,\n>    reg_errcode_t err;\n>    re_dfastate_t *newstate;\n>  \n> -  newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1);\n> +  newstate = (re_dfastate_t *) calloc (1, sizeof (re_dfastate_t));\n>    if (BE (newstate == NULL, 0))\n>      return NULL;\n>    err = re_node_set_init_copy (&newstate->nodes, nodes);\n> @@ -1679,7 +1679,7 @@ create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,\n>    reg_errcode_t err;\n>    re_dfastate_t *newstate;\n>  \n> -  newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1);\n> +  newstate = (re_dfastate_t *) calloc (1, sizeof (re_dfastate_t));\n>    if (BE (newstate == NULL, 0))\n>      return NULL;\n>    err = re_node_set_init_copy (&newstate->nodes, nodes);\n> diff --git a/compat/regex/regexec.c b/compat/regex/regexec.c\n> index eb5e1d4..edfe0c6 100644\n> --- a/compat/regex/regexec.c\n> +++ b/compat/regex/regexec.c\n> @@ -2797,8 +2797,8 @@ get_subexp (re_match_context_t *mctx, int bkref_node, int bkref_str_idx)\n>  \t    continue; /* No.  */\n>  \t  if (sub_top->path == NULL)\n>  \t    {\n> -\t      sub_top->path = calloc (sizeof (state_array_t),\n> -\t\t\t\t      sl_str - sub_top->str_idx + 1);\n> +\t      sub_top->path = calloc (sl_str - sub_top->str_idx + 1,\n> +\t\t\t\t      sizeof (state_array_t));\n>  \t      if (sub_top->path == NULL)\n>  \t\treturn REG_ESPACE;\n>  \t    }\n> @@ -3362,7 +3362,7 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state)\n>        if (ndests == 0)\n>  \t{\n>  \t  state->trtable = (re_dfastate_t **)\n> -\t    calloc (sizeof (re_dfastate_t *), SBC_MAX);\n> +\t    calloc (SBC_MAX, sizeof (re_dfastate_t *));\n>  \t  return 1;\n>  \t}\n>        return 0;\n> @@ -3458,7 +3458,7 @@ out_free:\n>  \t discern by looking at the character code: allocate a\n>  \t 256-entry transition table.  */\n>        trtable = state->trtable =\n> -\t(re_dfastate_t **) calloc (sizeof (re_dfastate_t *), SBC_MAX);\n> +\t(re_dfastate_t **) calloc (SBC_MAX, sizeof (re_dfastate_t *));\n>        if (BE (trtable == NULL, 0))\n>  \tgoto out_free;\n>  \n> @@ -3489,7 +3489,7 @@ out_free:\n>  \t transition tables, one starting at trtable[0] and one\n>  \t starting at trtable[SBC_MAX].  */\n>        trtable = state->word_trtable =\n> -\t(re_dfastate_t **) calloc (sizeof (re_dfastate_t *), 2 * SBC_MAX);\n> +\t(re_dfastate_t **) calloc (2 * SBC_MAX, sizeof (re_dfastate_t *));\n>        if (BE (trtable == NULL, 0))\n>  \tgoto out_free;\n>  \n> diff --git a/imap-send.c b/imap-send.c\n> index 524fbab..02eb3e0 100644\n> --- a/imap-send.c\n> +++ b/imap-send.c\n> @@ -954,7 +954,7 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc)\n>  \n>  \tctx = xcalloc(1, sizeof(*ctx));\n>  \n> -\tctx->imap = imap = xcalloc(sizeof(*imap), 1);\n> +\tctx->imap = imap = xcalloc(1, sizeof(*imap));\n>  \timap->buf.sock.fd[0] = imap->buf.sock.fd[1] = -1;\n>  \timap->in_progress_append = &imap->in_progress;\n"},{"id":"248774","messageId":"CAJFMrCFq3sdrdEYEPEPfp4xzZ2n_rbYR9cmMus0Dy5J1WX76Dg@mail.gmail.com","threadId":"37449","inReplyTo":"xmqqegvt27ac.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH] fix calloc() and xcalloc() argument ordering","fromName":"Arjun Sreedharan","fromEmail":"arjun024@gmail.com","sentAt":"2014-09-03T06:30:39Z","receivedAt":"2014-09-03T06:30:39Z","isPatch":true,"sender":{"key":"arjun024@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2861611?v=4"},"body":"On 3 September 2014 00:12, Junio C Hamano <gitster@pobox.com> wrote:\n> Arjun Sreedharan <arjun024@gmail.com> writes:\n>\n>> @number first, @size second argument.\n>>\n>> Signed-off-by: Arjun Sreedharan <arjun024@gmail.com>\n>> ---\n>>  builtin/for-each-ref.c        |  2 +-\n>\n> Thanks.  compat/regex/ being borrowed code, I'd prefer not to touch\n> them, though.\n>\n\nOk. should i resend?\n\n>>  compat/regex/regcomp.c        | 12 ++++++------\n>>  compat/regex/regex_internal.c |  4 ++--\n>>  compat/regex/regexec.c        | 10 +++++-----\n>>  imap-send.c                   |  2 +-\n>>  5 files changed, 15 insertions(+), 15 deletions(-)\n>>\n>> diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c\n>> index 47bd624..69bba06 100644\n>> --- a/builtin/for-each-ref.c\n>> +++ b/builtin/for-each-ref.c\n>> @@ -633,7 +633,7 @@ static void populate_value(struct refinfo *ref)\n>>       unsigned long size;\n>>       const unsigned char *tagged;\n>>\n>> -     ref->value = xcalloc(sizeof(struct atom_value), used_atom_cnt);\n>> +     ref->value = xcalloc(used_atom_cnt, sizeof(struct atom_value));\n>>\n>>       if (need_symref && (ref->flag & REF_ISSYMREF) && !ref->symref) {\n>>               unsigned char unused1[20];\n>> diff --git a/compat/regex/regcomp.c b/compat/regex/regcomp.c\n>> index 06f3088..e375c50 100644\n>> --- a/compat/regex/regcomp.c\n>> +++ b/compat/regex/regcomp.c\n>> @@ -861,7 +861,7 @@ init_dfa (re_dfa_t *dfa, size_t pat_len)\n>>      if (table_size > pat_len)\n>>        break;\n>>\n>> -  dfa->state_table = calloc (sizeof (struct re_state_table_entry), table_size);\n>> +  dfa->state_table = calloc (table_size, sizeof (struct re_state_table_entry));\n>>    dfa->state_hash_mask = table_size - 1;\n>>\n>>    dfa->mb_cur_max = MB_CUR_MAX;\n>> @@ -929,7 +929,7 @@ init_dfa (re_dfa_t *dfa, size_t pat_len)\n>>       {\n>>         int i, j, ch;\n>>\n>> -       dfa->sb_char = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);\n>> +       dfa->sb_char = (re_bitset_ptr_t) calloc (1, sizeof (bitset_t));\n>>         if (BE (dfa->sb_char == NULL, 0))\n>>           return REG_ESPACE;\n>>\n>> @@ -3072,9 +3072,9 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,\n>>                                                  _NL_COLLATE_SYMB_EXTRAMB);\n>>      }\n>>  #endif\n>> -  sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);\n>> +  sbcset = (re_bitset_ptr_t) calloc (1, sizeof (bitset_t));\n>>  #ifdef RE_ENABLE_I18N\n>> -  mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);\n>> +  mbcset = (re_charset_t *) calloc (1, sizeof (re_charset_t));\n>>  #endif /* RE_ENABLE_I18N */\n>>  #ifdef RE_ENABLE_I18N\n>>    if (BE (sbcset == NULL || mbcset == NULL, 0))\n>> @@ -3619,9 +3619,9 @@ build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans,\n>>    re_token_t br_token;\n>>    bin_tree_t *tree;\n>>\n>> -  sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);\n>> +  sbcset = (re_bitset_ptr_t) calloc (1, sizeof (bitset_t));\n>>  #ifdef RE_ENABLE_I18N\n>> -  mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);\n>> +  mbcset = (re_charset_t *) calloc (1, sizeof (re_charset_t));\n>>  #endif /* RE_ENABLE_I18N */\n>>\n>>  #ifdef RE_ENABLE_I18N\n>> diff --git a/compat/regex/regex_internal.c b/compat/regex/regex_internal.c\n>> index d4121f2..9d9e986 100644\n>> --- a/compat/regex/regex_internal.c\n>> +++ b/compat/regex/regex_internal.c\n>> @@ -1629,7 +1629,7 @@ create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes,\n>>    reg_errcode_t err;\n>>    re_dfastate_t *newstate;\n>>\n>> -  newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1);\n>> +  newstate = (re_dfastate_t *) calloc (1, sizeof (re_dfastate_t));\n>>    if (BE (newstate == NULL, 0))\n>>      return NULL;\n>>    err = re_node_set_init_copy (&newstate->nodes, nodes);\n>> @@ -1679,7 +1679,7 @@ create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,\n>>    reg_errcode_t err;\n>>    re_dfastate_t *newstate;\n>>\n>> -  newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1);\n>> +  newstate = (re_dfastate_t *) calloc (1, sizeof (re_dfastate_t));\n>>    if (BE (newstate == NULL, 0))\n>>      return NULL;\n>>    err = re_node_set_init_copy (&newstate->nodes, nodes);\n>> diff --git a/compat/regex/regexec.c b/compat/regex/regexec.c\n>> index eb5e1d4..edfe0c6 100644\n>> --- a/compat/regex/regexec.c\n>> +++ b/compat/regex/regexec.c\n>> @@ -2797,8 +2797,8 @@ get_subexp (re_match_context_t *mctx, int bkref_node, int bkref_str_idx)\n>>           continue; /* No.  */\n>>         if (sub_top->path == NULL)\n>>           {\n>> -           sub_top->path = calloc (sizeof (state_array_t),\n>> -                                   sl_str - sub_top->str_idx + 1);\n>> +           sub_top->path = calloc (sl_str - sub_top->str_idx + 1,\n>> +                                   sizeof (state_array_t));\n>>             if (sub_top->path == NULL)\n>>               return REG_ESPACE;\n>>           }\n>> @@ -3362,7 +3362,7 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state)\n>>        if (ndests == 0)\n>>       {\n>>         state->trtable = (re_dfastate_t **)\n>> -         calloc (sizeof (re_dfastate_t *), SBC_MAX);\n>> +         calloc (SBC_MAX, sizeof (re_dfastate_t *));\n>>         return 1;\n>>       }\n>>        return 0;\n>> @@ -3458,7 +3458,7 @@ out_free:\n>>        discern by looking at the character code: allocate a\n>>        256-entry transition table.  */\n>>        trtable = state->trtable =\n>> -     (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), SBC_MAX);\n>> +     (re_dfastate_t **) calloc (SBC_MAX, sizeof (re_dfastate_t *));\n>>        if (BE (trtable == NULL, 0))\n>>       goto out_free;\n>>\n>> @@ -3489,7 +3489,7 @@ out_free:\n>>        transition tables, one starting at trtable[0] and one\n>>        starting at trtable[SBC_MAX].  */\n>>        trtable = state->word_trtable =\n>> -     (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), 2 * SBC_MAX);\n>> +     (re_dfastate_t **) calloc (2 * SBC_MAX, sizeof (re_dfastate_t *));\n>>        if (BE (trtable == NULL, 0))\n>>       goto out_free;\n>>\n>> diff --git a/imap-send.c b/imap-send.c\n>> index 524fbab..02eb3e0 100644\n>> --- a/imap-send.c\n>> +++ b/imap-send.c\n>> @@ -954,7 +954,7 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc)\n>>\n>>       ctx = xcalloc(1, sizeof(*ctx));\n>>\n>> -     ctx->imap = imap = xcalloc(sizeof(*imap), 1);\n>> +     ctx->imap = imap = xcalloc(1, sizeof(*imap));\n>>       imap->buf.sock.fd[0] = imap->buf.sock.fd[1] = -1;\n>>       imap->in_progress_append = &imap->in_progress;\n"},{"id":"248835","messageId":"1409839395-1902-1-git-send-email-arjun024@gmail.com","threadId":"37449","inReplyTo":"xmqqegvt27ac.fsf@gitster.dls.corp.google.com","subject":"[PATCH] fix calloc() and xcalloc() argument ordering","fromName":"Arjun Sreedharan","fromEmail":"arjun024@gmail.com","sentAt":"2014-09-04T14:03:15Z","receivedAt":"2014-09-04T14:03:15Z","isPatch":true,"sender":{"key":"arjun024@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2861611?v=4"},"body":"@number first, @size second argument.\n\nSigned-off-by: Arjun Sreedharan <arjun024@gmail.com>\n---\n builtin/for-each-ref.c | 2 +-\n imap-send.c            | 2 +-\n 2 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c\nindex 47bd624..69bba06 100644\n--- a/builtin/for-each-ref.c\n+++ b/builtin/for-each-ref.c\n@@ -633,7 +633,7 @@ static void populate_value(struct refinfo *ref)\n \tunsigned long size;\n \tconst unsigned char *tagged;\n \n-\tref->value = xcalloc(sizeof(struct atom_value), used_atom_cnt);\n+\tref->value = xcalloc(used_atom_cnt, sizeof(struct atom_value));\n \n \tif (need_symref && (ref->flag & REF_ISSYMREF) && !ref->symref) {\n \t\tunsigned char unused1[20];\ndiff --git a/imap-send.c b/imap-send.c\nindex 524fbab..02eb3e0 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -954,7 +954,7 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc)\n \n \tctx = xcalloc(1, sizeof(*ctx));\n \n-\tctx->imap = imap = xcalloc(sizeof(*imap), 1);\n+\tctx->imap = imap = xcalloc(1, sizeof(*imap));\n \timap->buf.sock.fd[0] = imap->buf.sock.fd[1] = -1;\n \timap->in_progress_append = &imap->in_progress;\n \n-- \n1.8.1.msysgit.1\n"}]}