diff options
| author | Gustavo André dos Santos Lopes <cataphract@php.net> | 2011-02-01 18:11:16 +0000 |
|---|---|---|
| committer | Gustavo André dos Santos Lopes <cataphract@php.net> | 2011-02-01 18:11:16 +0000 |
| commit | c6ccc4328560799f8532e0dd14fecea46245db15 (patch) | |
| tree | 5393e1bc57758244af82e37a57182233594b5c46 /main | |
| parent | 44cd358f04249852e724c4288ef6b0584fad0354 (diff) | |
| download | php-git-c6ccc4328560799f8532e0dd14fecea46245db15.tar.gz | |
- 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
Diffstat (limited to 'main')
| -rw-r--r-- | main/network.c | 3 | ||||
| -rw-r--r-- | main/streams/filter.c | 2 | ||||
| -rwxr-xr-x | main/streams/streams.c | 24 |
3 files changed, 17 insertions, 12 deletions
diff --git a/main/network.c b/main/network.c index a4377f2022..0cfd777e4a 100644 --- a/main/network.c +++ b/main/network.c @@ -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 */ diff --git a/main/streams/filter.c b/main/streams/filter.c index fb825f51e1..623c66f96d 100644 --- a/main/streams/filter.c +++ b/main/streams/filter.c @@ -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; } diff --git a/main/streams/streams.c b/main/streams/streams.c index 57dfbf150f..99f9fdc415 100755 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -940,6 +940,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; @@ -950,6 +951,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; } @@ -960,6 +963,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; @@ -972,12 +976,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; } } @@ -989,17 +998,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 */ |
