cvs: php-src /main/streams streams.c
| From: | Sara Golemon | Date: | Wed, 15 Mar 2006 21:18:36 +0000 |
| Subject: | cvs: php-src /main/streams streams.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-37290@lists.php.net to get a copy of this message | ||
pollita Wed Mar 15 21:18:36 2006 UTC
Modified files:
/php-src/main/streams streams.c
Log:
Fix improper byte count on partial reads
http://cvs.php.net/viewcvs.cgi/php-src/main/streams/streams.c?r1=1.103&r2=1.104&diff_format=u
Index: php-src/main/streams/streams.c
diff -u php-src/main/streams/streams.c:1.103 php-src/main/streams/streams.c:1.104
--- php-src/main/streams/streams.c:1.103 Wed Mar 15 00:28:57 2006
+++ php-src/main/streams/streams.c Wed Mar 15 21:18:36 2006
@@ -19,7 +19,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: streams.c,v 1.103 2006/03/15 00:28:57 pollita Exp $ */
+/* $Id: streams.c,v 1.104 2006/03/15 21:18:36 pollita Exp $ */
#define _GNU_SOURCE
#include "php.h"
@@ -424,6 +424,10 @@
TODO: Needs better handling of surrogate pairs */
static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_DC)
{
+ if (stream->readpos == stream->writepos) {
+ stream->readpos = stream->writepos = 0;
+ }
+
/* allocate/fill the buffer */
if (stream->readfilters.head) {
@@ -573,7 +577,7 @@
/* reduce buffer memory consumption if possible, to avoid a realloc */
if (stream->readbuf.s && stream->readbuflen - stream->writepos <
stream->chunk_size) {
- memmove(stream->readbuf.s, stream->readbuf.s + stream->readpos, stream->readbuflen
- stream->readpos);
+ memmove(stream->readbuf.s, stream->readbuf.s + stream->readpos, stream->writepos -
stream->readpos);
stream->writepos -= stream->readpos;
stream->readpos = 0;
}
@@ -605,7 +609,7 @@
* drain the remainder of the buffer before using the "raw" read mode for
* the excess */
if (stream->writepos - stream->readpos > 0) {
- toread = UBYTES(stream->writepos - stream->readpos);
+ toread = PS_ULEN(stream->input_encoding, stream->writepos - stream->readpos);
if (toread > size) {
toread = size;
@@ -1038,8 +1042,8 @@
* than 8K, we waste 1 byte per additional 8K or so.
* That seems acceptable to me, to avoid making this code
* hard to follow */
- bufstart.s = erealloc(bufstart.s, PS_ULEN(stream, current_buf_size + cpysz + 1));
- buf.s = bufstart.s + PS_ULEN(stream, total_copied);
+ bufstart.s = erealloc(bufstart.s, PS_ULEN(stream->input_encoding, current_buf_size + cpysz +
1));
+ buf.s = bufstart.s + PS_ULEN(stream->input_encoding, total_copied);
current_buf_size += cpysz + 1;
} else {
if (cpysz >= maxlen - 1) {
@@ -1121,8 +1125,6 @@
return bufstart.s;
}
-/* Same deal as php_stream_read() and php_stream_get_line()
- * Will give unexpected results if used against a unicode stream */
PHPAPI char *php_stream_get_record(php_stream *stream, size_t maxlen, size_t *returned_len, char
*delim, size_t delim_len TSRMLS_DC)
{
char *e, *buf;