tony2001 Thu Apr 6 19:11:06 2006 UTC
Modified files:
/php-src/ext/spl spl_directory.c
Log:
MF51: fix #36981 (SplFileObject->fgets() ignores max_length)
http://cvs.php.net/viewcvs.cgi/php-src/ext/spl/spl_directory.c?r1=1.88&r2=1.89&diff_format=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.88
php-src/ext/spl/spl_directory.c:1.89
--- php-src/ext/spl/spl_directory.c:1.88 Wed Mar 29 15:08:52 2006
+++ php-src/ext/spl/spl_directory.c Thu Apr 6 19:11:06 2006
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: spl_directory.c,v 1.88 2006/03/29 15:08:52 tony2001 Exp $ */
+/* $Id: spl_directory.c,v 1.89 2006/04/06 19:11:06 tony2001 Exp $ */
#ifdef HAVE_CONFIG_H
# include "config.h"
@@ -1335,7 +1335,7 @@
static int spl_filesystem_file_read(spl_filesystem_object *intern, int silent
TSRMLS_DC) /* {{{ */
{
char *buf;
- size_t line_len;
+ size_t line_len = 0;
long line_add = (intern->u.file.current_line ||
intern->u.file.current_zval) ? 1 : 0;
spl_filesystem_file_free_line(intern TSRMLS_CC);
@@ -1347,7 +1347,17 @@
return FAILURE;
}
- buf = php_stream_get_line(intern->u.file.stream, NULL_ZSTR,
intern->u.file.max_line_len, &line_len);
+ if (intern->u.file.max_line_len > 0) {
+ buf = emalloc((intern->u.file.max_line_len + 1) * sizeof(char));
+ if (php_stream_get_line(intern->u.file.stream, buf,
intern->u.file.max_line_len, &line_len) == NULL) {
+ efree(buf);
+ buf = NULL;
+ } else {
+ buf[line_len] = '\0';
+ }
+ } else {
+ buf = php_stream_get_line(intern->u.file.stream, NULL_ZSTR, 0,
&line_len);
+ }
if (!buf) {
intern->u.file.current_line = estrdup("");
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php