Skip to content

Commit 3c024a9

Browse files
bjoriderickr
authored andcommitted
Properly initialize the zval* we are working with
1 parent 6a3c2d6 commit 3c024a9

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/bson.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,11 +549,16 @@ bool php_phongo_bson_visit_document(const bson_iter_t *iter ARG_UNUSED, const ch
549549
TSRMLS_FETCH();
550550

551551
if (bson_iter_init(&child, v_document)) {
552+
#if PHP_VERSION_ID >= 70000
553+
zval zv;
554+
#endif
552555
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER;
553556

554557
state.map = ((php_phongo_bson_state *)data)->map;
555558

556-
#if PHP_VERSION_ID < 70000
559+
#if PHP_VERSION_ID >= 70000
560+
state.zchild = &zv;
561+
#else
557562
MAKE_STD_ZVAL(state.zchild);
558563
#endif
559564
array_init(state.zchild);
@@ -612,12 +617,18 @@ bool php_phongo_bson_visit_array(const bson_iter_t *iter ARG_UNUSED, const char
612617

613618
if (bson_iter_init(&child, v_array)) {
614619
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER;
620+
#if PHP_VERSION_ID >= 70000
621+
zval zv;
622+
#endif
615623

616624
state.map = ((php_phongo_bson_state *)data)->map;
617625

618-
#if PHP_VERSION_ID < 70000
626+
#if PHP_VERSION_ID >= 70000
627+
state.zchild = &zv;
628+
#else
619629
MAKE_STD_ZVAL(state.zchild);
620630
#endif
631+
621632
array_init(state.zchild);
622633

623634
if (!bson_iter_visit_all(&child, &php_bson_visitors, &state)) {
@@ -1173,15 +1184,20 @@ int bson_to_zval(const unsigned char *data, int data_len, zval **zv)
11731184
int retval = 0;
11741185
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER;
11751186

1187+
#if PHP_VERSION_ID >= 70000
1188+
state.zchild = *zv;
1189+
#endif
11761190
retval = bson_to_zval_ex(data, data_len, &state);
1191+
#if PHP_VERSION_ID < 70000
11771192
*zv = state.zchild;
1193+
#endif
11781194

11791195
return retval;
11801196
}
11811197
int bson_to_zval_ex(const unsigned char *data, int data_len, php_phongo_bson_state *state)
11821198
{
11831199
#if PHP_VERSION_ID >= 70000
1184-
zval zv;
1200+
zval zv;
11851201
#endif
11861202
bson_reader_t *reader;
11871203
bson_iter_t iter;

0 commit comments

Comments
 (0)