]> granicus.if.org Git - php/commitdiff
MFH: improve checks and fix #38251
authorAntony Dovgal <tony2001@php.net>
Sun, 30 Jul 2006 11:56:07 +0000 (11:56 +0000)
committerAntony Dovgal <tony2001@php.net>
Sun, 30 Jul 2006 11:56:07 +0000 (11:56 +0000)
ext/sockets/sockets.c

index 831fa8952a608650c2516238063a8abb3cf76ae0..561dc775e0034bd71d5ab2dea590db2efecf76d5 100644 (file)
@@ -515,6 +515,7 @@ PHP_RSHUTDOWN_FUNCTION(sockets)
 int php_sock_array_to_fd_set(zval *sock_array, fd_set *fds, SOCKET *max_fd TSRMLS_DC) {
        zval            **element;
        php_socket      *php_sock;
+       int                     num = 0;
        
        if (Z_TYPE_P(sock_array) != IS_ARRAY) return 0;
 
@@ -529,9 +530,10 @@ int php_sock_array_to_fd_set(zval *sock_array, fd_set *fds, SOCKET *max_fd TSRML
                if (php_sock->bsd_socket > *max_fd) {
                        *max_fd = php_sock->bsd_socket;
                }
+               num++;
        }
 
-       return 1;
+       return num ? 1 : 0;
 }
 
 int php_sock_array_from_fd_set(zval *sock_array, fd_set *fds TSRMLS_DC) {
@@ -539,6 +541,8 @@ int php_sock_array_from_fd_set(zval *sock_array, fd_set *fds TSRMLS_DC) {
        zval            **dest_element;
        php_socket      *php_sock;
        HashTable       *new_hash;
+       int                     num = 0;
+
        if (Z_TYPE_P(sock_array) != IS_ARRAY) return 0;
 
        ALLOC_HASHTABLE(new_hash);
@@ -555,6 +559,7 @@ int php_sock_array_from_fd_set(zval *sock_array, fd_set *fds TSRMLS_DC) {
                        zend_hash_next_index_insert(new_hash, (void *)element, sizeof(zval *), (void **)&dest_element);
                        if (dest_element) zval_add_ref(dest_element);
                }
+               num++;
        }
 
        /* Destroy old array, add new one */
@@ -564,7 +569,7 @@ int php_sock_array_from_fd_set(zval *sock_array, fd_set *fds TSRMLS_DC) {
        zend_hash_internal_pointer_reset(new_hash);
        Z_ARRVAL_P(sock_array) = new_hash;
 
-       return 1;
+       return num ? 1 : 0;
 }