@@ -451,8 +451,7 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
451451 bool control_value_alloc = false;
452452 int rc = LDAP_SUCCESS ;
453453
454- val = zend_hash_find (control_ht , ZSTR_KNOWN (ZEND_STR_VALUE ));
455- if (val != NULL ) {
454+ if ((val = zend_hash_find (control_ht , ZSTR_KNOWN (ZEND_STR_VALUE ))) != NULL ) {
456455 if (Z_TYPE_P (val ) != IS_ARRAY ) {
457456 tmpstring = zval_try_get_string (val );
458457 if (!tmpstring ) {
@@ -462,14 +461,13 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
462461 control_value .bv_val = ZSTR_VAL (tmpstring );
463462 control_value .bv_len = ZSTR_LEN (tmpstring );
464463 } else if (zend_string_equals_literal (control_oid , LDAP_CONTROL_PAGEDRESULTS )) {
465- zval * tmp = zend_hash_str_find ( Z_ARRVAL_P ( val ), "size" , sizeof ( "size" ) - 1 ) ;
464+ zval * tmp ;
466465 int pagesize = 1 ;
467466 struct berval cookie = { 0L , NULL };
468- if (tmp != NULL ) {
467+ if (( tmp = zend_hash_str_find ( Z_ARRVAL_P ( val ), "size" , sizeof ( "size" ) - 1 )) != NULL ) {
469468 pagesize = zval_get_long (tmp );
470469 }
471- tmp = zend_hash_str_find (Z_ARRVAL_P (val ), "cookie" , sizeof ("cookie" ) - 1 );
472- if (tmp != NULL ) {
470+ if ((tmp = zend_hash_str_find (Z_ARRVAL_P (val ), "cookie" , sizeof ("cookie" ) - 1 )) != NULL ) {
473471 tmpstring = zval_try_get_string (tmp );
474472 if (!tmpstring ) {
475473 rc = -1 ;
@@ -485,8 +483,8 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
485483 php_error_docref (NULL , E_WARNING , "Failed to create paged result control value: %s (%d)" , ldap_err2string (rc ), rc );
486484 }
487485 } else if (zend_string_equals_literal (control_oid , LDAP_CONTROL_ASSERT )) {
488- zval * tmp = zend_hash_str_find ( Z_ARRVAL_P ( val ), "filter" , sizeof ( "filter" ) - 1 ) ;
489- if (tmp == NULL ) {
486+ zval * tmp ;
487+ if (( tmp = zend_hash_str_find ( Z_ARRVAL_P ( val ), "filter" , sizeof ( "filter" ) - 1 )) == NULL ) {
490488 rc = -1 ;
491489 zend_value_error ("%s(): Control must have a \"filter\" key" , get_active_function_name ());
492490 } else {
@@ -508,8 +506,8 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
508506 zend_string_release (assert );
509507 }
510508 } else if (zend_string_equals_literal (control_oid , LDAP_CONTROL_VALUESRETURNFILTER )) {
511- zval * tmp = zend_hash_str_find ( Z_ARRVAL_P ( val ), "filter" , sizeof ( "filter" ) - 1 ) ;
512- if (tmp == NULL ) {
509+ zval * tmp ;
510+ if (( tmp = zend_hash_str_find ( Z_ARRVAL_P ( val ), "filter" , sizeof ( "filter" ) - 1 )) == NULL ) {
513511 rc = -1 ;
514512 zend_value_error ("%s(): Control must have a \"filter\" key" , get_active_function_name ());
515513 } else {
@@ -532,8 +530,8 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
532530 }
533531 }
534532 } else if (zend_string_equals_literal (control_oid , LDAP_CONTROL_PRE_READ ) || zend_string_equals_literal (control_oid , LDAP_CONTROL_POST_READ )) {
535- zval * tmp = zend_hash_str_find ( Z_ARRVAL_P ( val ), "attrs" , sizeof ( "attrs" ) - 1 ) ;
536- if (tmp == NULL ) {
533+ zval * tmp ;
534+ if (( tmp = zend_hash_str_find ( Z_ARRVAL_P ( val ), "attrs" , sizeof ( "attrs" ) - 1 )) == NULL ) {
537535 rc = -1 ;
538536 zend_value_error ("%s(): Control must have an \"attrs\" key" , get_active_function_name ());
539537 } else {
@@ -543,14 +541,15 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
543541 rc = -1 ;
544542 php_error_docref (NULL , E_WARNING , "Failed to allocate control value" );
545543 } else {
544+ zval * attr ;
545+
546546 uint32_t num_attribs = zend_hash_num_elements (Z_ARRVAL_P (tmp ));
547547 ldap_attrs = safe_emalloc ((num_attribs + 1 ), sizeof (char * ), 0 );
548548 tmpstrings1 = safe_emalloc (num_attribs , sizeof (zend_string * ), 0 );
549549 num_tmpstrings1 = 0 ;
550550
551551 for (uint32_t i = 0 ; i < num_attribs ; i ++ ) {
552- zval * attr = zend_hash_index_find (Z_ARRVAL_P (tmp ), i );
553- if (attr == NULL ) {
552+ if ((attr = zend_hash_index_find (Z_ARRVAL_P (tmp ), i )) == NULL ) {
554553 rc = -1 ;
555554 php_error_docref (NULL , E_WARNING , "Failed to encode attribute list" );
556555 goto failure ;
@@ -582,6 +581,8 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
582581 }
583582 }
584583 } else if (zend_string_equals_literal (control_oid , LDAP_CONTROL_SORTREQUEST )) {
584+ zval * sortkey , * tmp ;
585+
585586 uint32_t num_keys = zend_hash_num_elements (Z_ARRVAL_P (val ));
586587 sort_keys = safe_emalloc ((num_keys + 1 ), sizeof (LDAPSortKey * ), 0 );
587588 tmpstrings1 = safe_emalloc (num_keys , sizeof (zend_string * ), 0 );
@@ -590,15 +591,13 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
590591 num_tmpstrings2 = 0 ;
591592
592593 for (uint32_t i = 0 ; i < num_keys ; i ++ ) {
593- zval * sortkey = zend_hash_index_find (Z_ARRVAL_P (val ), i );
594- if (sortkey == NULL ) {
594+ if ((sortkey = zend_hash_index_find (Z_ARRVAL_P (val ), i )) == NULL ) {
595595 rc = -1 ;
596596 php_error_docref (NULL , E_WARNING , "Failed to encode sort keys list" );
597597 goto failure ;
598598 }
599599
600- zval * tmp = zend_hash_str_find (Z_ARRVAL_P (sortkey ), "attr" , sizeof ("attr" ) - 1 );
601- if (tmp == NULL ) {
600+ if ((tmp = zend_hash_str_find (Z_ARRVAL_P (sortkey ), "attr" , sizeof ("attr" ) - 1 )) == NULL ) {
602601 rc = -1 ;
603602 zend_value_error ("%s(): Sort key list must have an \"attr\" key" , get_active_function_name ());
604603 goto failure ;
@@ -612,8 +611,7 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
612611 sort_keys [i ]-> attributeType = ZSTR_VAL (tmpstrings1 [num_tmpstrings1 ]);
613612 ++ num_tmpstrings1 ;
614613
615- tmp = zend_hash_str_find (Z_ARRVAL_P (sortkey ), "oid" , sizeof ("oid" ) - 1 );
616- if (tmp == NULL ) {
614+ if ((tmp = zend_hash_str_find (Z_ARRVAL_P (sortkey ), "oid" , sizeof ("oid" ) - 1 )) != NULL ) {
617615 tmpstrings2 [num_tmpstrings2 ] = zval_try_get_string (tmp );
618616 if (!tmpstrings2 [num_tmpstrings2 ]) {
619617 rc = -1 ;
@@ -625,8 +623,7 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
625623 sort_keys [i ]-> orderingRule = NULL ;
626624 }
627625
628- tmp = zend_hash_str_find (Z_ARRVAL_P (sortkey ), "reverse" , sizeof ("reverse" ) - 1 );
629- if (tmp == NULL ) {
626+ if ((tmp = zend_hash_str_find (Z_ARRVAL_P (sortkey ), "reverse" , sizeof ("reverse" ) - 1 )) != NULL ) {
630627 sort_keys [i ]-> reverseOrder = zend_is_true (tmp );
631628 } else {
632629 sort_keys [i ]-> reverseOrder = 0 ;
@@ -640,30 +637,28 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
640637 php_error_docref (NULL , E_WARNING , "Failed to create sort control value: %s (%d)" , ldap_err2string (rc ), rc );
641638 }
642639 } else if (zend_string_equals_literal (control_oid , LDAP_CONTROL_VLVREQUEST )) {
640+ zval * tmp ;
643641 LDAPVLVInfo vlvInfo ;
644642 struct berval attrValue ;
645643 struct berval context ;
646644
647- zval * tmp = zend_hash_str_find (Z_ARRVAL_P (val ), "before" , sizeof ("before" ) - 1 );
648- if (tmp != NULL ) {
645+ if ((tmp = zend_hash_str_find (Z_ARRVAL_P (val ), "before" , sizeof ("before" ) - 1 )) != NULL ) {
649646 vlvInfo .ldvlv_before_count = zval_get_long (tmp );
650647 } else {
651648 rc = -1 ;
652649 zend_value_error ("%s(): Array value for VLV control must have a \"before\" key" , get_active_function_name ());
653650 goto failure ;
654651 }
655652
656- tmp = zend_hash_str_find (Z_ARRVAL_P (val ), "after" , sizeof ("after" ) - 1 );
657- if (tmp != NULL ) {
653+ if ((tmp = zend_hash_str_find (Z_ARRVAL_P (val ), "after" , sizeof ("after" ) - 1 )) != NULL ) {
658654 vlvInfo .ldvlv_after_count = zval_get_long (tmp );
659655 } else {
660656 rc = -1 ;
661657 zend_value_error ("%s(): Array value for VLV control must have an \"after\" key" , get_active_function_name ());
662658 goto failure ;
663659 }
664660
665- tmp = zend_hash_str_find (Z_ARRVAL_P (val ), "attrvalue" , sizeof ("attrvalue" ) - 1 );
666- if (tmp != NULL ) {
661+ if ((tmp = zend_hash_str_find (Z_ARRVAL_P (val ), "attrvalue" , sizeof ("attrvalue" ) - 1 )) != NULL ) {
667662 tmpstring = zval_try_get_string (tmp );
668663 if (!tmpstring ) {
669664 rc = -1 ;
@@ -676,9 +671,8 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
676671 vlvInfo .ldvlv_attrvalue = NULL ;
677672 vlvInfo .ldvlv_offset = zval_get_long (tmp );
678673 /* Find "count" key */
679- zval * count_key = zend_hash_find (Z_ARRVAL_P (val ), ZSTR_KNOWN (ZEND_STR_COUNT ));
680- if (count_key != NULL ) {
681- vlvInfo .ldvlv_count = zval_get_long (count_key );
674+ if ((tmp = zend_hash_find (Z_ARRVAL_P (val ), ZSTR_KNOWN (ZEND_STR_COUNT ))) != NULL ) {
675+ vlvInfo .ldvlv_count = zval_get_long (tmp );
682676 } else {
683677 rc = -1 ;
684678 zend_value_error ("%s(): Array value for VLV control must have a \"count\" key" , get_active_function_name ());
@@ -691,8 +685,7 @@ static int php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, const HashT
691685 }
692686
693687 zend_string * context_str = NULL ;
694- tmp = zend_hash_str_find (Z_ARRVAL_P (val ), "context" , sizeof ("context" ) - 1 );
695- if (tmp != NULL ) {
688+ if ((tmp = zend_hash_str_find (Z_ARRVAL_P (val ), "context" , sizeof ("context" ) - 1 )) != NULL ) {
696689 context_str = zval_try_get_string (tmp );
697690 if (!context_str ) {
698691 rc = -1 ;
@@ -1868,6 +1861,7 @@ PHP_FUNCTION(ldap_first_entry)
18681861 zval * link , * result ;
18691862 ldap_linkdata * ld ;
18701863 ldap_resultdata * ldap_result ;
1864+ LDAPMessage * entry ;
18711865
18721866 if (zend_parse_parameters (ZEND_NUM_ARGS (), "OO" , & link , ldap_link_ce , & result , ldap_result_ce ) != SUCCESS ) {
18731867 RETURN_THROWS ();
@@ -1879,8 +1873,7 @@ PHP_FUNCTION(ldap_first_entry)
18791873 ldap_result = Z_LDAP_RESULT_P (result );
18801874 VERIFY_LDAP_RESULT_OPEN (ldap_result );
18811875
1882- LDAPMessage * entry = ldap_first_entry (ld -> link , ldap_result -> result );
1883- if (entry == NULL ) {
1876+ if ((entry = ldap_first_entry (ld -> link , ldap_result -> result )) == NULL ) {
18841877 RETVAL_FALSE ;
18851878 } else {
18861879 object_init_ex (return_value , ldap_result_entry_ce );
@@ -1898,6 +1891,7 @@ PHP_FUNCTION(ldap_next_entry)
18981891 zval * link , * result_entry ;
18991892 ldap_linkdata * ld ;
19001893 ldap_result_entry * resultentry ;
1894+ LDAPMessage * entry_next ;
19011895
19021896 if (zend_parse_parameters (ZEND_NUM_ARGS (), "OO" , & link , ldap_link_ce , & result_entry , ldap_result_entry_ce ) != SUCCESS ) {
19031897 RETURN_THROWS ();
@@ -1908,8 +1902,7 @@ PHP_FUNCTION(ldap_next_entry)
19081902
19091903 resultentry = Z_LDAP_RESULT_ENTRY_P (result_entry );
19101904
1911- LDAPMessage * entry_next = ldap_next_entry (ld -> link , resultentry -> data );
1912- if (entry_next == NULL ) {
1905+ if ((entry_next = ldap_next_entry (ld -> link , resultentry -> data )) == NULL ) {
19131906 RETVAL_FALSE ;
19141907 } else {
19151908 object_init_ex (return_value , ldap_result_entry_ce );
@@ -2026,6 +2019,7 @@ PHP_FUNCTION(ldap_first_attribute)
20262019 zval * link , * result_entry ;
20272020 ldap_linkdata * ld ;
20282021 ldap_result_entry * resultentry ;
2022+ char * attribute ;
20292023
20302024 if (zend_parse_parameters (ZEND_NUM_ARGS (), "OO" , & link , ldap_link_ce , & result_entry , ldap_result_entry_ce ) != SUCCESS ) {
20312025 RETURN_THROWS ();
@@ -2036,8 +2030,7 @@ PHP_FUNCTION(ldap_first_attribute)
20362030
20372031 resultentry = Z_LDAP_RESULT_ENTRY_P (result_entry );
20382032
2039- char * attribute = ldap_first_attribute (ld -> link , resultentry -> data , & resultentry -> ber );
2040- if (attribute == NULL ) {
2033+ if ((attribute = ldap_first_attribute (ld -> link , resultentry -> data , & resultentry -> ber )) == NULL ) {
20412034 RETURN_FALSE ;
20422035 } else {
20432036 RETVAL_STRING (attribute );
@@ -2054,6 +2047,7 @@ PHP_FUNCTION(ldap_next_attribute)
20542047 zval * link , * result_entry ;
20552048 ldap_linkdata * ld ;
20562049 ldap_result_entry * resultentry ;
2050+ char * attribute ;
20572051
20582052 if (zend_parse_parameters (ZEND_NUM_ARGS (), "OO" , & link , ldap_link_ce , & result_entry , ldap_result_entry_ce ) != SUCCESS ) {
20592053 RETURN_THROWS ();
@@ -2069,8 +2063,7 @@ PHP_FUNCTION(ldap_next_attribute)
20692063 RETURN_FALSE ;
20702064 }
20712065
2072- char * attribute = ldap_next_attribute (ld -> link , resultentry -> data , resultentry -> ber );
2073- if (attribute == NULL ) {
2066+ if ((attribute = ldap_next_attribute (ld -> link , resultentry -> data , resultentry -> ber )) == NULL ) {
20742067#if (LDAP_API_VERSION > 2000 ) || defined(HAVE_ORALDAP )
20752068 if (resultentry -> ber != NULL ) {
20762069 ber_free (resultentry -> ber , 0 );
@@ -2148,6 +2141,7 @@ PHP_FUNCTION(ldap_get_values_len)
21482141 ldap_linkdata * ld ;
21492142 ldap_result_entry * resultentry ;
21502143 char * attr ;
2144+ struct berval * * ldap_value_len ;
21512145 int num_values ;
21522146 size_t attr_len ;
21532147
@@ -2160,8 +2154,7 @@ PHP_FUNCTION(ldap_get_values_len)
21602154
21612155 resultentry = Z_LDAP_RESULT_ENTRY_P (result_entry );
21622156
2163- struct berval * * ldap_value_len = ldap_get_values_len (ld -> link , resultentry -> data , attr );
2164- if (ldap_value_len == NULL ) {
2157+ if ((ldap_value_len = ldap_get_values_len (ld -> link , resultentry -> data , attr )) == NULL ) {
21652158 php_error_docref (NULL , E_WARNING , "Cannot get the value(s) of attribute %s" , ldap_err2string (_get_lderrno (ld -> link )));
21662159 RETURN_FALSE ;
21672160 }
@@ -2214,15 +2207,14 @@ PHP_FUNCTION(ldap_get_dn)
22142207PHP_FUNCTION (ldap_explode_dn )
22152208{
22162209 zend_long with_attrib ;
2217- char * dn ;
2210+ char * dn , * * ldap_value ;
22182211 size_t dn_len ;
22192212
22202213 if (zend_parse_parameters (ZEND_NUM_ARGS (), "pl" , & dn , & dn_len , & with_attrib ) != SUCCESS ) {
22212214 RETURN_THROWS ();
22222215 }
22232216
2224- char * * ldap_value = ldap_explode_dn (dn , with_attrib );
2225- if (ldap_value == NULL ) {
2217+ if (!(ldap_value = ldap_explode_dn (dn , with_attrib ))) {
22262218 /* Invalid parameters were passed to ldap_explode_dn */
22272219 RETURN_FALSE ;
22282220 }
@@ -3530,6 +3522,7 @@ PHP_FUNCTION(ldap_first_reference)
35303522 zval * link , * result ;
35313523 ldap_linkdata * ld ;
35323524 ldap_resultdata * ldap_result ;
3525+ LDAPMessage * entry ;
35333526
35343527 if (zend_parse_parameters (ZEND_NUM_ARGS (), "OO" , & link , ldap_link_ce , & result , ldap_result_ce ) != SUCCESS ) {
35353528 RETURN_THROWS ();
@@ -3541,8 +3534,7 @@ PHP_FUNCTION(ldap_first_reference)
35413534 ldap_result = Z_LDAP_RESULT_P (result );
35423535 VERIFY_LDAP_RESULT_OPEN (ldap_result );
35433536
3544- LDAPMessage * entry = ldap_first_reference (ld -> link , ldap_result -> result );
3545- if (entry == NULL ) {
3537+ if ((entry = ldap_first_reference (ld -> link , ldap_result -> result )) == NULL ) {
35463538 RETVAL_FALSE ;
35473539 } else {
35483540 object_init_ex (return_value , ldap_result_entry_ce );
@@ -3560,6 +3552,7 @@ PHP_FUNCTION(ldap_next_reference)
35603552 zval * link , * result_entry ;
35613553 ldap_linkdata * ld ;
35623554 ldap_result_entry * resultentry ;
3555+ LDAPMessage * entry_next ;
35633556
35643557 if (zend_parse_parameters (ZEND_NUM_ARGS (), "OO" , & link , ldap_link_ce , & result_entry , ldap_result_entry_ce ) != SUCCESS ) {
35653558 RETURN_THROWS ();
@@ -3570,8 +3563,7 @@ PHP_FUNCTION(ldap_next_reference)
35703563
35713564 resultentry = Z_LDAP_RESULT_ENTRY_P (result_entry );
35723565
3573- LDAPMessage * entry_next = ldap_first_reference (ld -> link , resultentry -> data );
3574- if (entry_next == NULL ) {
3566+ if ((entry_next = ldap_next_reference (ld -> link , resultentry -> data )) == NULL ) {
35753567 RETVAL_FALSE ;
35763568 } else {
35773569 object_init_ex (return_value , ldap_result_entry_ce );
0 commit comments