cataphract                               Tue, 01 Feb 2011 18:11:16 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=307923

Log:
- Fixed several comparisons that always result in true of false
  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

Changed paths:
    U   php/php-src/trunk/ext/standard/streamsfuncs.c
    U   php/php-src/trunk/main/network.c
    U   php/php-src/trunk/main/streams/filter.c
    U   php/php-src/trunk/main/streams/streams.c

Modified: php/php-src/trunk/ext/standard/streamsfuncs.c
===================================================================
--- php/php-src/trunk/ext/standard/streamsfuncs.c       2011-02-01 18:10:35 UTC 
(rev 307922)
+++ php/php-src/trunk/ext/standard/streamsfuncs.c       2011-02-01 18:11:16 UTC 
(rev 307923)
@@ -634,7 +634,7 @@
                 * 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);

@@ -686,7 +686,7 @@
                 * 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)) {
                                if (type == HASH_KEY_IS_LONG) {
                                        zend_hash_index_update(new_hash, 
num_ind, (void *)elem, sizeof(zval *), (void **)&dest_elem);

Modified: php/php-src/trunk/main/network.c
===================================================================
--- php/php-src/trunk/main/network.c    2011-02-01 18:10:35 UTC (rev 307922)
+++ php/php-src/trunk/main/network.c    2011-02-01 18:11:16 UTC (rev 307923)
@@ -1133,7 +1133,8 @@
 {
        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 */

Modified: php/php-src/trunk/main/streams/filter.c
===================================================================
--- php/php-src/trunk/main/streams/filter.c     2011-02-01 18:10:35 UTC (rev 
307922)
+++ php/php-src/trunk/main/streams/filter.c     2011-02-01 18:11:16 UTC (rev 
307923)
@@ -360,7 +360,7 @@
                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;
                }

Modified: php/php-src/trunk/main/streams/streams.c
===================================================================
--- php/php-src/trunk/main/streams/streams.c    2011-02-01 18:10:35 UTC (rev 
307922)
+++ php/php-src/trunk/main/streams/streams.c    2011-02-01 18:11:16 UTC (rev 
307923)
@@ -940,6 +940,7 @@

        len = stream->writepos - stream->readpos;

+       /* make sure the stream read buffer has maxlen bytes */
        while (len < maxlen) {

                size_t just_read;
@@ -950,6 +951,8 @@
                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;
                }
@@ -960,6 +963,7 @@
        } 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;
@@ -972,12 +976,17 @@
                }

                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;
                }
        }
@@ -989,17 +998,12 @@
        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 */

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to