Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit af87ade

Browse files
Cleanup php_posix_group_to_array() (#18497)
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 g is pointless as every callee already handles that in a better way.
1 parent 1fa076e commit af87ade

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

‎ext/posix/posix.c‎

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -659,16 +659,12 @@ PHP_FUNCTION(posix_mknod)
659659

660660
/* Takes a pointer to posix group and a pointer to an already initialized ZVAL
661661
* array container and fills the array with the posix group member data. */
662-
int php_posix_group_to_array(struct group *g, zval *array_group) /* {{{ */
662+
staticvoid php_posix_group_to_array(struct group *g, zval *array_group) /* {{{ */
663663
{
664664
zval array_members;
665665
int count;
666666

667-
if (NULL == g)
668-
return 0;
669-
670-
if (array_group == NULL || Z_TYPE_P(array_group) != IS_ARRAY)
671-
return 0;
667+
ZEND_ASSERT(Z_TYPE_P(array_group) == IS_ARRAY);
672668

673669
array_init(&array_members);
674670
zend_hash_real_init_packed(Z_ARRVAL(array_members));
@@ -691,7 +687,6 @@ int php_posix_group_to_array(struct group *g, zval *array_group) /* {{{ */
691687
}
692688
zend_hash_str_update(Z_ARRVAL_P(array_group), "members", sizeof("members")-1, &array_members);
693689
add_assoc_long(array_group, "gid", g->gr_gid);
694-
return 1;
695690
}
696691
/* }}} */
697692

@@ -833,11 +828,7 @@ PHP_FUNCTION(posix_getgrnam)
833828
#endif
834829
array_init(return_value);
835830

836-
if (!php_posix_group_to_array(g, return_value)) {
837-
zend_array_destroy(Z_ARR_P(return_value));
838-
php_error_docref(NULL, E_WARNING, "Unable to convert posix group to array");
839-
RETVAL_FALSE;
840-
}
831+
php_posix_group_to_array(g, return_value);
841832
#if defined(ZTS) && defined(HAVE_GETGRNAM_R) && defined(_SC_GETGR_R_SIZE_MAX)
842833
efree(buf);
843834
#endif
@@ -895,11 +886,7 @@ PHP_FUNCTION(posix_getgrgid)
895886
#endif
896887
array_init(return_value);
897888

898-
if (!php_posix_group_to_array(g, return_value)) {
899-
zend_array_destroy(Z_ARR_P(return_value));
900-
php_error_docref(NULL, E_WARNING, "Unable to convert posix group struct to array");
901-
RETVAL_FALSE;
902-
}
889+
php_posix_group_to_array(g, return_value);
903890
#if defined(ZTS) && defined(HAVE_GETGRGID_R) && defined(_SC_GETGR_R_SIZE_MAX)
904891
efree(grbuf);
905892
#endif

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /