Skip to content

Commit c6e6f5e

Browse files
committed
do not pass value to callback if not sert
1 parent 6cbd97e commit c6e6f5e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

git2_tree.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,15 @@ static int git2_treewalk_cb(const char *root, const git_tree_entry *entry, void
9595

9696
ZVAL_STRING(&argv[0], root);
9797
git2_tree_entry_spawn_ephemeral(&argv[1], entry);
98-
ZVAL_COPY_VALUE(&argv[2], p->callback_data);
98+
99+
if (p->callback_data) {
100+
ZVAL_COPY_VALUE(&argv[2], p->callback_data);
101+
p->callback_i.param_count = 3;
102+
} else {
103+
p->callback_i.param_count = 2;
104+
}
99105

100106
p->callback_i.retval = &retval;
101-
p->callback_i.param_count = 3;
102107
p->callback_i.params = argv;
103108

104109
error = zend_call_function(&p->callback_i, &p->callback_ic);
@@ -128,11 +133,13 @@ static PHP_METHOD(Tree, walk) {
128133
long mode;
129134
struct git2_treewalk_payload p;
130135
p.this = getThis();
136+
p.callback_data = NULL;
131137

132138
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lf|z", &mode, &p.callback_i, &p.callback_ic, &p.callback_data) != SUCCESS) {
133139
return;
134140
}
135141

142+
136143
GIT2_TREE_FETCH();
137144

138145
switch(mode) {

0 commit comments

Comments
 (0)