Skip to content

Commit 713dfd7

Browse files
committed
Better fstat
1 parent 2586812 commit 713dfd7

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

ext/spl/spl_directory.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2552,12 +2552,12 @@ PHP_METHOD(SplFileObject, flock)
25522552
spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(ZEND_THIS);
25532553
zend_function *func_ptr;
25542554

2555-
func_ptr = (zend_function *)zend_hash_str_find_ptr(EG(function_table), "flock", sizeof("flock") - 1);
2556-
if (func_ptr == NULL) {
2555+
func_ptr = (zend_function *)zend_hash_str_find_ptr(EG(function_table), "flock", sizeof("flock") - 1);
2556+
if (func_ptr == NULL) {
25572557
zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Internal error, function flock() not found. Please report");
25582558
RETURN_THROWS();
2559-
}
2560-
spl_filesystem_file_call(intern, func_ptr, ZEND_NUM_ARGS(), return_value);
2559+
}
2560+
spl_filesystem_file_call(intern, func_ptr, ZEND_NUM_ARGS(), return_value);
25612561
}
25622562
/* }}} */
25632563

@@ -2669,12 +2669,12 @@ PHP_METHOD(SplFileObject, fscanf)
26692669
spl_filesystem_file_free_line(intern);
26702670
intern->u.file.current_line_num++;
26712671

2672-
func_ptr = (zend_function *)zend_hash_str_find_ptr(EG(function_table), "fscanf", sizeof("fscanf") - 1);
2673-
if (func_ptr == NULL) {
2672+
func_ptr = (zend_function *)zend_hash_str_find_ptr(EG(function_table), "fscanf", sizeof("fscanf") - 1);
2673+
if (func_ptr == NULL) {
26742674
zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Internal error, function fscanf() not found. Please report");
26752675
RETURN_THROWS();
2676-
}
2677-
spl_filesystem_file_call(intern, func_ptr, ZEND_NUM_ARGS(), return_value);
2676+
}
2677+
spl_filesystem_file_call(intern, func_ptr, ZEND_NUM_ARGS(), return_value);
26782678
}
26792679
/* }}} */
26802680

@@ -2748,12 +2748,22 @@ PHP_METHOD(SplFileObject, fstat)
27482748
spl_filesystem_object *intern = Z_SPLFILESYSTEM_P(ZEND_THIS);
27492749
zend_function *func_ptr;
27502750

2751-
func_ptr = (zend_function *)zend_hash_str_find_ptr(EG(function_table), "fstat", sizeof("fstat") - 1);
2752-
if (func_ptr == NULL) {
2751+
if (zend_parse_parameters_none() == FAILURE) {
2752+
RETURN_THROWS();
2753+
}
2754+
2755+
func_ptr = (zend_function *)zend_hash_str_find_ptr(EG(function_table), "fstat", sizeof("fstat") - 1);
2756+
if (func_ptr == NULL) {
27532757
zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Internal error, function fstat() not found. Please report");
27542758
RETURN_THROWS();
2755-
}
2756-
spl_filesystem_file_call(intern, func_ptr, ZEND_NUM_ARGS(), return_value);
2759+
}
2760+
2761+
if (Z_ISUNDEF_P(&intern->u.file.zresource)) {
2762+
zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized");
2763+
RETURN_THROWS();
2764+
}
2765+
2766+
zend_call_known_function(func_ptr, NULL, NULL, return_value, 0, NULL, NULL);
27572767
}
27582768
/* }}} */
27592769

0 commit comments

Comments
 (0)