Skip to content

Commit 4bb157d

Browse files
committed
Address review feedback: use struct copy for save/restore, cleanup.
- Save/restore EG(errors) with struct copy instead of 3 separate vars - Remove extra blank line left from zend_init_errors_buf removal - Restore early return in zend_free_recorded_errors to skip memset
1 parent 49c8d34 commit 4bb157d

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

Zend/zend.c

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,6 @@ static FILE *zend_fopen_wrapper(zend_string *filename, zend_string **opened_path
643643
}
644644
/* }}} */
645645

646-
647646
#ifdef ZTS
648647
static bool short_tags_default = true;
649648
static uint32_t compiler_options_default = ZEND_COMPILE_DEFAULT;
@@ -1446,9 +1445,7 @@ ZEND_API ZEND_COLD void zend_error_zstr_at(
14461445
zend_stack delayed_oplines_stack;
14471446
int type = orig_type & E_ALL;
14481447
bool orig_record_errors;
1449-
uint32_t orig_num_errors = 0;
1450-
uint32_t orig_cap_errors = 0;
1451-
zend_error_info **orig_errors = NULL;
1448+
struct zend_err_buf orig_errors_buf = {0};
14521449
zend_result res;
14531450

14541451
/* If we're executing a function during SCCP, count any warnings that may be emitted,
@@ -1461,9 +1458,7 @@ ZEND_API ZEND_COLD void zend_error_zstr_at(
14611458

14621459
/* Emit any delayed error before handling fatal error */
14631460
if ((type & E_FATAL_ERRORS) && !(type & E_DONT_BAIL) && EG(errors).size) {
1464-
uint32_t num_errors = EG(errors).size;
1465-
uint32_t cap_errors = EG(errors).capacity;
1466-
zend_error_info **errors = EG(errors).errors;
1461+
struct zend_err_buf errors_buf = EG(errors);
14671462
EG(errors).size = 0;
14681463

14691464
bool orig_record_errors = EG(record_errors);
@@ -1474,13 +1469,11 @@ ZEND_API ZEND_COLD void zend_error_zstr_at(
14741469
int orig_user_error_handler_error_reporting = EG(user_error_handler_error_reporting);
14751470
EG(user_error_handler_error_reporting) = 0;
14761471

1477-
zend_emit_recorded_errors_ex(num_errors, errors);
1472+
zend_emit_recorded_errors_ex(errors_buf.size, errors_buf.errors);
14781473

14791474
EG(user_error_handler_error_reporting) = orig_user_error_handler_error_reporting;
14801475
EG(record_errors) = orig_record_errors;
1481-
EG(errors).size = num_errors;
1482-
EG(errors).capacity = cap_errors;
1483-
EG(errors).errors = errors;
1476+
EG(errors) = errors_buf;
14841477
}
14851478

14861479
if (EG(record_errors)) {
@@ -1580,18 +1573,13 @@ ZEND_API ZEND_COLD void zend_error_zstr_at(
15801573
orig_record_errors = EG(record_errors);
15811574
EG(record_errors) = false;
15821575

1583-
orig_num_errors = EG(errors).size;
1584-
orig_cap_errors = EG(errors).capacity;
1585-
orig_errors = EG(errors).errors;
1576+
orig_errors_buf = EG(errors);
15861577
memset(&EG(errors), 0, sizeof(EG(errors)));
15871578

15881579
res = call_user_function(CG(function_table), NULL, &orig_user_error_handler, &retval, 4, params);
15891580

15901581
EG(record_errors) = orig_record_errors;
1591-
1592-
EG(errors).capacity = orig_cap_errors;
1593-
EG(errors).size = orig_num_errors;
1594-
EG(errors).errors = orig_errors;
1582+
EG(errors) = orig_errors_buf;
15951583

15961584
if (res == SUCCESS) {
15971585
if (Z_TYPE(retval) != IS_UNDEF) {
@@ -1805,15 +1793,17 @@ ZEND_API void zend_emit_recorded_errors(void)
18051793

18061794
ZEND_API void zend_free_recorded_errors(void)
18071795
{
1796+
if (!EG(errors).size) {
1797+
return;
1798+
}
1799+
18081800
for (uint32_t i = 0; i < EG(errors).size; i++) {
18091801
zend_error_info *info = EG(errors).errors[i];
18101802
zend_string_release(info->filename);
18111803
zend_string_release(info->message);
18121804
efree_size(info, sizeof(zend_error_info));
18131805
}
1814-
if (EG(errors).errors) {
1815-
efree(EG(errors).errors);
1816-
}
1806+
efree(EG(errors).errors);
18171807
memset(&EG(errors), 0, sizeof(EG(errors)));
18181808
}
18191809

0 commit comments

Comments
 (0)