Skip to content

Commit dfea790

Browse files
René Scharfegitster
authored andcommitted
remove ecb parameter from xdi_diff_outf()
xdi_diff_outf() overrides the structure members of its last parameter, ignoring any value that callers pass in. It's no surprise then that all callers pass a pointer to an uninitialized structure. They also don't read it after the call, so the parameter is neither used for input nor for output. Turn it into a local variable of xdi_diff_outf(). Signed-off-by: Rene Scharfe <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ed215b1 commit dfea790

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
lines changed

combine-diff.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ static void combine_diff(const unsigned char *parent, unsigned int mode,
211211
xpparam_t xpp;
212212
xdemitconf_t xecfg;
213213
mmfile_t parent_file;
214-
xdemitcb_t ecb;
215214
struct combine_diff_state state;
216215
unsigned long sz;
217216

@@ -231,7 +230,7 @@ static void combine_diff(const unsigned char *parent, unsigned int mode,
231230
state.n = n;
232231

233232
xdi_diff_outf(&parent_file, result_file, consume_line, &state,
234-
&xpp, &xecfg, &ecb);
233+
&xpp, &xecfg);
235234
free(parent_file.ptr);
236235

237236
/* Assign line numbers for this parent.

diff.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,6 @@ static void diff_words_show(struct diff_words_data *diff_words)
696696
{
697697
xpparam_t xpp;
698698
xdemitconf_t xecfg;
699-
xdemitcb_t ecb;
700699
mmfile_t minus, plus;
701700

702701
/* special case: only removal */
@@ -718,7 +717,7 @@ static void diff_words_show(struct diff_words_data *diff_words)
718717
/* as only the hunk header will be parsed, we need a 0-context */
719718
xecfg.ctxlen = 0;
720719
xdi_diff_outf(&minus, &plus, fn_out_diff_words_aux, diff_words,
721-
&xpp, &xecfg, &ecb);
720+
&xpp, &xecfg);
722721
free(minus.ptr);
723722
free(plus.ptr);
724723
if (diff_words->current_plus != diff_words->plus.text.ptr +
@@ -1704,7 +1703,6 @@ static void builtin_diff(const char *name_a,
17041703
const char *diffopts = getenv("GIT_DIFF_OPTS");
17051704
xpparam_t xpp;
17061705
xdemitconf_t xecfg;
1707-
xdemitcb_t ecb;
17081706
struct emit_callback ecbdata;
17091707
const struct userdiff_funcname *pe;
17101708

@@ -1776,7 +1774,7 @@ static void builtin_diff(const char *name_a,
17761774
}
17771775
}
17781776
xdi_diff_outf(&mf1, &mf2, fn_out_consume, &ecbdata,
1779-
&xpp, &xecfg, &ecb);
1777+
&xpp, &xecfg);
17801778
if (DIFF_OPT_TST(o, COLOR_DIFF_WORDS))
17811779
free_diff_words_data(&ecbdata);
17821780
if (textconv_one)
@@ -1829,13 +1827,12 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
18291827
/* Crazy xdl interfaces.. */
18301828
xpparam_t xpp;
18311829
xdemitconf_t xecfg;
1832-
xdemitcb_t ecb;
18331830

18341831
memset(&xpp, 0, sizeof(xpp));
18351832
memset(&xecfg, 0, sizeof(xecfg));
18361833
xpp.flags = XDF_NEED_MINIMAL | o->xdl_opts;
18371834
xdi_diff_outf(&mf1, &mf2, diffstat_consume, diffstat,
1838-
&xpp, &xecfg, &ecb);
1835+
&xpp, &xecfg);
18391836
}
18401837

18411838
free_and_return:
@@ -1877,14 +1874,13 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
18771874
/* Crazy xdl interfaces.. */
18781875
xpparam_t xpp;
18791876
xdemitconf_t xecfg;
1880-
xdemitcb_t ecb;
18811877

18821878
memset(&xpp, 0, sizeof(xpp));
18831879
memset(&xecfg, 0, sizeof(xecfg));
18841880
xecfg.ctxlen = 1; /* at least one context line */
18851881
xpp.flags = XDF_NEED_MINIMAL;
18861882
xdi_diff_outf(&mf1, &mf2, checkdiff_consume, &data,
1887-
&xpp, &xecfg, &ecb);
1883+
&xpp, &xecfg);
18881884

18891885
if (data.ws_rule & WS_BLANK_AT_EOF) {
18901886
struct emit_callback ecbdata;
@@ -3361,7 +3357,6 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
33613357
for (i = 0; i < q->nr; i++) {
33623358
xpparam_t xpp;
33633359
xdemitconf_t xecfg;
3364-
xdemitcb_t ecb;
33653360
mmfile_t mf1, mf2;
33663361
struct diff_filepair *p = q->queue[i];
33673362
int len1, len2;
@@ -3423,7 +3418,7 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
34233418
xecfg.ctxlen = 3;
34243419
xecfg.flags = XDL_EMIT_FUNCNAMES;
34253420
xdi_diff_outf(&mf1, &mf2, patch_id_consume, &data,
3426-
&xpp, &xecfg, &ecb);
3421+
&xpp, &xecfg);
34273422
}
34283423

34293424
git_SHA1_Final(sha1, &ctx);

xdiff-interface.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,20 @@ int xdi_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdemitconf_t co
138138

139139
int xdi_diff_outf(mmfile_t *mf1, mmfile_t *mf2,
140140
xdiff_emit_consume_fn fn, void *consume_callback_data,
141-
xpparam_t const *xpp,
142-
xdemitconf_t const *xecfg, xdemitcb_t *xecb)
141+
xpparam_t const *xpp, xdemitconf_t const *xecfg)
143142
{
144143
int ret;
145144
struct xdiff_emit_state state;
145+
xdemitcb_t ecb;
146146

147147
memset(&state, 0, sizeof(state));
148148
state.consume = fn;
149149
state.consume_callback_data = consume_callback_data;
150-
xecb->outf = xdiff_outf;
151-
xecb->priv = &state;
150+
memset(&ecb, 0, sizeof(ecb));
151+
ecb.outf = xdiff_outf;
152+
ecb.priv = &state;
152153
strbuf_init(&state.remainder, 0);
153-
ret = xdi_diff(mf1, mf2, xpp, xecfg, xecb);
154+
ret = xdi_diff(mf1, mf2, xpp, xecfg, &ecb);
154155
strbuf_release(&state.remainder);
155156
return ret;
156157
}

xdiff-interface.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ typedef void (*xdiff_emit_hunk_consume_fn)(void *, long, long, long);
99
int xdi_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdemitconf_t const *xecfg, xdemitcb_t *ecb);
1010
int xdi_diff_outf(mmfile_t *mf1, mmfile_t *mf2,
1111
xdiff_emit_consume_fn fn, void *consume_callback_data,
12-
xpparam_t const *xpp,
13-
xdemitconf_t const *xecfg, xdemitcb_t *xecb);
12+
xpparam_t const *xpp, xdemitconf_t const *xecfg);
1413
int xdi_diff_hunks(mmfile_t *mf1, mmfile_t *mf2,
1514
xdiff_emit_hunk_consume_fn fn, void *consume_callback_data,
1615
xpparam_t const *xpp, xdemitconf_t *xecfg);

0 commit comments

Comments
 (0)