Skip to content

Commit 007b02c

Browse files
committed
fix MT serialize
1 parent d31ab90 commit 007b02c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

ext/random/random.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,8 @@ static int mersennetwister_serialize(void *state, HashTable *data) {
504504
}
505505
ZVAL_LONG(&tmp, s->cnt);
506506
zend_hash_next_index_insert(data, &tmp);
507+
ZVAL_LONG(&tmp, s->mode);
508+
zend_hash_next_index_insert(data, &tmp);
507509
ZVAL_LONG(&tmp, s->seeded);
508510
zend_hash_next_index_insert(data, &tmp);
509511

@@ -523,12 +525,17 @@ static int mersennetwister_unserialize(void *state, HashTable *data) {
523525

524526
s->s[i] = Z_LVAL_P(tmp);
525527
}
526-
tmp = zend_hash_index_find(data, MT_N); /* cnt */
528+
tmp = zend_hash_index_find(data, MT_N);
527529
if (!tmp || Z_TYPE_P(tmp) != IS_LONG) {
528530
return FAILURE;
529531
}
530532
s->cnt = Z_LVAL_P(tmp);
531-
tmp = zend_hash_index_find(data, MT_N + 1); /* seeded */
533+
tmp = zend_hash_index_find(data, MT_N + 1);
534+
if (!tmp || Z_TYPE_P(tmp) != IS_LONG) {
535+
return FAILURE;
536+
}
537+
s->mode = Z_LVAL_P(tmp);
538+
tmp = zend_hash_index_find(data, MT_N + 2);
532539
if (!tmp || Z_TYPE_P(tmp) != IS_LONG) {
533540
return FAILURE;
534541
}

0 commit comments

Comments
 (0)