Skip to content

Commit 1fa076e

Browse files
authored
Cleanup php_posix_passwd_to_array() (#18496)
This function can be static, and the error checks are pointless: 1. It's guaranteed that the return value is an array by now, as it is always preceded by array_init(return_value). 2. The null check for pw is pointless as every callee already handles that in a better way.
1 parent e80d953 commit 1fa076e

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

ext/posix/posix.c

+4-16
Original file line numberDiff line numberDiff line change
@@ -906,12 +906,9 @@ PHP_FUNCTION(posix_getgrgid)
906906
}
907907
/* }}} */
908908

909-
int php_posix_passwd_to_array(struct passwd *pw, zval *return_value) /* {{{ */
909+
static void php_posix_passwd_to_array(struct passwd *pw, zval *return_value) /* {{{ */
910910
{
911-
if (NULL == pw)
912-
return 0;
913-
if (NULL == return_value || Z_TYPE_P(return_value) != IS_ARRAY)
914-
return 0;
911+
ZEND_ASSERT(Z_TYPE_P(return_value) == IS_ARRAY);
915912

916913
add_assoc_string(return_value, "name", pw->pw_name);
917914
add_assoc_string(return_value, "passwd", pw->pw_passwd);
@@ -920,7 +917,6 @@ int php_posix_passwd_to_array(struct passwd *pw, zval *return_value) /* {{{ */
920917
add_assoc_string(return_value, "gecos", pw->pw_gecos);
921918
add_assoc_string(return_value, "dir", pw->pw_dir);
922919
add_assoc_string(return_value, "shell", pw->pw_shell);
923-
return 1;
924920
}
925921
/* }}} */
926922

@@ -973,11 +969,7 @@ PHP_FUNCTION(posix_getpwnam)
973969
#endif
974970
array_init(return_value);
975971

976-
if (!php_posix_passwd_to_array(pw, return_value)) {
977-
zend_array_destroy(Z_ARR_P(return_value));
978-
php_error_docref(NULL, E_WARNING, "Unable to convert posix passwd struct to array");
979-
RETVAL_FALSE;
980-
}
972+
php_posix_passwd_to_array(pw, return_value);
981973
#if defined(ZTS) && defined(_SC_GETPW_R_SIZE_MAX) && defined(HAVE_GETPWNAM_R)
982974
efree(buf);
983975
#endif
@@ -1033,11 +1025,7 @@ PHP_FUNCTION(posix_getpwuid)
10331025
#endif
10341026
array_init(return_value);
10351027

1036-
if (!php_posix_passwd_to_array(pw, return_value)) {
1037-
zend_array_destroy(Z_ARR_P(return_value));
1038-
php_error_docref(NULL, E_WARNING, "Unable to convert posix passwd struct to array");
1039-
RETVAL_FALSE;
1040-
}
1028+
php_posix_passwd_to_array(pw, return_value);
10411029
#if defined(ZTS) && defined(_SC_GETPW_R_SIZE_MAX) && defined(HAVE_GETPWUID_R)
10421030
efree(pwbuf);
10431031
#endif

0 commit comments

Comments
 (0)