compat/regex: fix argument order to calloc(3)
Windows compiler suddenly started complaining that calloc(3) takes its arguments in <nmemb, size> order. Indeed, there are many calls that has their arguments in a _wrong_ order. Fix them all. A sample breakage can be seen at https://github.com/git/git/actions/runs/9046793153/job/24857988702#step:4:272 [Backported from f01301aabe1 (compat/regex: fix argument order to calloc(3), 2024-05-11).] Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Junio C Hamano committed
May 11, 2024 at 23:25 UTC
7e6073d27083054773f3c3b21a608f400cf7348d
3 files changed
+13
-13
compat/regex/regcomp.c
+6
-6
@@ -868,7 +868,7 @@ init_dfa (re_dfa_t *dfa, size_t pat_len)
868
if (table_size > pat_len)
869
break;
870
871
- dfa->state_table = calloc (sizeof (struct re_state_table_entry), table_size);
871
+ dfa->state_table = calloc (table_size, sizeof (struct re_state_table_entry));
872
dfa->state_hash_mask = table_size - 1;
873
874
dfa->mb_cur_max = MB_CUR_MAX;
@@ -936,7 +936,7 @@ init_dfa (re_dfa_t *dfa, size_t pat_len)
936
{
937
int i, j, ch;
938
939
- dfa->sb_char = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
939
+ dfa->sb_char = (re_bitset_ptr_t) calloc (1, sizeof (bitset_t));
940
if (BE (dfa->sb_char == NULL, 0))
941
return REG_ESPACE;
942
@@ -3079,9 +3079,9 @@ parse_bracket_exp (re_string_t *regexp, re_dfa_t *dfa, re_token_t *token,
3079
_NL_COLLATE_SYMB_EXTRAMB);
3080
}
3081
#endif
3082
- sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
3082
+ sbcset = (re_bitset_ptr_t) calloc (1, sizeof (bitset_t));
3083
#ifdef RE_ENABLE_I18N
3084
- mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);
3084
+ mbcset = (re_charset_t *) calloc (1, sizeof (re_charset_t));
3085
#endif /* RE_ENABLE_I18N */
3086
#ifdef RE_ENABLE_I18N
3087
if (BE (sbcset == NULL || mbcset == NULL, 0))
@@ -3626,9 +3626,9 @@ build_charclass_op (re_dfa_t *dfa, RE_TRANSLATE_TYPE trans,
3626
re_token_t br_token;
3627
bin_tree_t *tree;
3628
3629
- sbcset = (re_bitset_ptr_t) calloc (sizeof (bitset_t), 1);
3629
+ sbcset = (re_bitset_ptr_t) calloc (1, sizeof (bitset_t));
3630
#ifdef RE_ENABLE_I18N
3631
- mbcset = (re_charset_t *) calloc (sizeof (re_charset_t), 1);
3631
+ mbcset = (re_charset_t *) calloc (1, sizeof (re_charset_t));
3632
#endif /* RE_ENABLE_I18N */
3633
3634
#ifdef RE_ENABLE_I18N
compat/regex/regex_internal.c
+2
-2
@@ -1628,7 +1628,7 @@ create_ci_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1628
reg_errcode_t err;
1629
re_dfastate_t *newstate;
1630
1631
- newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1);
1631
+ newstate = (re_dfastate_t *) calloc (1, sizeof (re_dfastate_t));
1632
if (BE (newstate == NULL, 0))
1633
return NULL;
1634
err = re_node_set_init_copy (&newstate->nodes, nodes);
@@ -1678,7 +1678,7 @@ create_cd_newstate (const re_dfa_t *dfa, const re_node_set *nodes,
1678
reg_errcode_t err;
1679
re_dfastate_t *newstate;
1680
1681
- newstate = (re_dfastate_t *) calloc (sizeof (re_dfastate_t), 1);
1681
+ newstate = (re_dfastate_t *) calloc (1, sizeof (re_dfastate_t));
1682
if (BE (newstate == NULL, 0))
1683
return NULL;
1684
err = re_node_set_init_copy (&newstate->nodes, nodes);
compat/regex/regexec.c
+5
-5
@@ -2796,8 +2796,8 @@ get_subexp (re_match_context_t *mctx, int bkref_node, int bkref_str_idx)
2796
continue; /* No. */
2797
if (sub_top->path == NULL)
2798
{
2799
- sub_top->path = calloc (sizeof (state_array_t),
2800
- sl_str - sub_top->str_idx + 1);
2799
+ sub_top->path = calloc (sl_str - sub_top->str_idx + 1,
2800
+ sizeof (state_array_t));
2801
if (sub_top->path == NULL)
2802
return REG_ESPACE;
2803
}
@@ -3361,7 +3361,7 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state)
3361
if (ndests == 0)
3362
{
3363
state->trtable = (re_dfastate_t **)
3364
- calloc (sizeof (re_dfastate_t *), SBC_MAX);
3364
+ calloc (SBC_MAX, sizeof (re_dfastate_t *));
3365
return 1;
3366
}
3367
return 0;
@@ -3457,7 +3457,7 @@ out_free:
3457
discern by looking at the character code: allocate a
3458
256-entry transition table. */
3459
trtable = state->trtable =
3460
- (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), SBC_MAX);
3460
+ (re_dfastate_t **) calloc (SBC_MAX, sizeof (re_dfastate_t *));
3461
if (BE (trtable == NULL, 0))
3462
goto out_free;
3463
@@ -3488,7 +3488,7 @@ out_free:
3488
transition tables, one starting at trtable[0] and one
3489
starting at trtable[SBC_MAX]. */
3490
trtable = state->word_trtable =
3491
- (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), 2 * SBC_MAX);
3491
+ (re_dfastate_t **) calloc (2 * SBC_MAX, sizeof (re_dfastate_t *));
3492
if (BE (trtable == NULL, 0))
3493
goto out_free;
3494