]> granicus.if.org Git - php/commitdiff
- Fixed several comparisons that always result in true of false
authorGustavo André dos Santos Lopes <cataphract@php.net>
Tue, 1 Feb 2011 18:10:35 +0000 (18:10 +0000)
committerGustavo André dos Santos Lopes <cataphract@php.net>
Tue, 1 Feb 2011 18:10:35 +0000 (18:10 +0000)
  due to signedness of one of the operands, either by removing
  dead code or fixing it.
- Thrown some comments around in php_stream_get_record.
- See http://www.mail-archive.com/internals@lists.php.net/msg49525.html

ext/standard/streamsfuncs.c
main/network.c
main/streams/filter.c
main/streams/streams.c

index 0b96a500b8783a56edb9fce15ab5f6692cf6556f..99b7e44e059562d83a10176c0f2d31405a9772a3 100644 (file)
@@ -634,7 +634,7 @@ static int stream_array_to_fd_set(zval *stream_array, fd_set *fds, php_socket_t
                 * when casting.  It is only used here so that the buffered data warning
                 * is not displayed.
                 * */
-               if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&this_fd, 1) && this_fd >= 0) {
+               if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&this_fd, 1) && this_fd != -1) {
 
                        PHP_SAFE_FD_SET(this_fd, fds);
 
@@ -674,7 +674,7 @@ static int stream_array_from_fd_set(zval *stream_array, fd_set *fds TSRMLS_DC)
                 * when casting.  It is only used here so that the buffered data warning
                 * is not displayed.
                 */
-               if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&this_fd, 1) && this_fd >= 0) {
+               if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&this_fd, 1) && this_fd != -1) {
                        if (PHP_SAFE_FD_ISSET(this_fd, fds)) {
                                zend_hash_next_index_insert(new_hash, (void *)elem, sizeof(zval *), (void **)&dest_elem);
                                if (dest_elem) {
index f410b9827c44d25f7625d68e93a1dcd0ea88ac8b..1133fc59016334e823a9bc72f2b18dfae5a1bcb6 100644 (file)
@@ -1133,7 +1133,8 @@ PHPAPI int php_poll2(php_pollfd *ufds, unsigned int nfds, int timeout)
 {
        fd_set rset, wset, eset;
        php_socket_t max_fd = SOCK_ERR;
-       unsigned int i, n;
+       unsigned int i;
+       int n;
        struct timeval tv;
 
        /* check the highest numbered descriptor */
index fb825f51e1429de71c8c860463ea24c76a6eea39..623c66f96da30b213ada8297ddf3f3da168c6bfa 100644 (file)
@@ -360,7 +360,7 @@ PHPAPI int php_stream_filter_append_ex(php_stream_filter_chain *chain, php_strea
                php_stream_bucket_append(brig_inp, bucket TSRMLS_CC);
                status = filter->fops->filter(stream, filter, brig_inp, brig_outp, &consumed, PSFS_FLAG_NORMAL TSRMLS_CC);
 
-               if (stream->readpos + consumed > (uint)stream->writepos || consumed < 0) {
+               if (stream->readpos + consumed > (uint)stream->writepos) {
                        /* No behaving filter should cause this. */
                        status = PSFS_ERR_FATAL;
                }
index faef5a3ab34dda4db7941c07b1f73a8446fbe4a1..9de8f2451c49599c308de6f40d2eb2495aadc022 100755 (executable)
@@ -869,6 +869,7 @@ PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *re
 
        len = stream->writepos - stream->readpos;
 
+       /* make sure the stream read buffer has maxlen bytes */
        while (len < maxlen) {
 
                size_t just_read;
@@ -879,6 +880,8 @@ PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *re
                just_read = (stream->writepos - stream->readpos) - len;
                len += just_read;
 
+               /* read operation have less data than request; assume the stream is
+                * temporarily or permanently out of data */
                if (just_read < toread) {
                        break;
                }
@@ -889,6 +892,7 @@ PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *re
        } else {
                size_t seek_len;
 
+               /* set the maximum number of bytes we're allowed to read from buffer */
                seek_len = stream->writepos - stream->readpos;
                if (seek_len > maxlen) {
                        seek_len = maxlen;
@@ -901,12 +905,17 @@ PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *re
                }
 
                if (!e) {
+                       /* return with error if the delimiter string was not found, we
+                        * could not completely fill the read buffer with maxlen bytes
+                        * and we don't know we've reached end of file. Added with
+                        * non-blocking streams in mind, where this situation is frequent */
                        if (seek_len < maxlen && !stream->eof) {
                                return NULL;
                        }
                        toread = maxlen;
                } else {
                        toread = e - (char *) stream->readbuf - stream->readpos;
+                       /* we found the delimiter, so advance the read pointer past it */
                        skip = 1;
                }
        }
@@ -918,17 +927,12 @@ PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *re
        buf = emalloc(toread + 1);
        *returned_len = php_stream_read(stream, buf, toread);
 
-       if (*returned_len >= 0) {
-               if (skip) {
-                       stream->readpos += delim_len;
-                       stream->position += delim_len;
-               }
-               buf[*returned_len] = '\0';
-               return buf;
-       } else {
-               efree(buf);
-               return NULL;
+       if (skip) {
+               stream->readpos += delim_len;
+               stream->position += delim_len;
        }
+       buf[*returned_len] = '\0';
+       return buf;
 }
 
 /* Writes a buffer directly to a stream, using multiple of the chunk size */